pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C pastebin - collaborative debugging tool View Help


Posted by solarwind on Wed 21 Jan 06:22
report abuse | download | new post

  1. #include <htc.h>
  2. #include <stdio.h>
  3.  
  4. typedef unsigned char byte;
  5.  
  6. __CONFIG(MCLRDIS & LVPDIS & FCMDIS & BORDIS & PWRTDIS & WDTDIS & UNPROTECT & IESODIS & INTIO);
  7. __CONFIG(BORV21);
  8.  
  9. #define _XTAL_FREQ 4000000
  10.  
  11. byte rx = 0x00;
  12.  
  13. void putch(unsigned char byte) {       
  14.         TXREG = byte;
  15.         while(TRMT == 0); //Wait while sending
  16. }
  17.  
  18. unsigned char getch() {
  19.         while(RCIF == 0); //Wait while receiving
  20.         return RCREG;
  21. }
  22.  
  23. void wt() {
  24.         byte b;
  25.         for(b = 0; b < 30; b++)
  26.                 __delay_ms(100);
  27. }
  28.  
  29. long int i = 0;
  30.  
  31. void main() {
  32.         //All ports are output
  33.         TRISA = 0x00;
  34.         TRISB = 0x00;
  35.         TRISC = 0b10000000; //RC7 is input for RX
  36.         TRISE = 0x00;
  37.        
  38.         //Turn off analog input
  39.         ANSEL = 0x00;
  40.         ANSELH = 0x00;
  41.        
  42.         //Disable comparators
  43.         C1ON = 0;
  44.         C2ON = 0;
  45.        
  46.         //Disable A2D
  47.         ADON = 0;
  48.        
  49.         //Disable CCP
  50.         CCP1CON = 0x00;
  51.         CCP2CON = 0x00;
  52.        
  53.         //Set up UART
  54.         SPBRG = 0x19; //9600 bps
  55.         TXSTA = 0b00100100;
  56.         RCSTA = 0b10010000;
  57.        
  58.         _delay(250);
  59.        
  60.         rx = RCREG;
  61.         rx = RCREG;
  62.         rx = RCREG;
  63.        
  64.         wt();
  65.        
  66.         while(1) {
  67.                 printf("%li Hello, world!\n", i);
  68.                 __delay_ms(100);
  69.                 i++;
  70.         }
  71.        
  72.         while(1) {
  73.                 putch(getch());
  74.         }       
  75.        
  76. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post