Advertisement
Guest User

solarwind

a guest
Jan 12th, 2009
1,710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <htc.h>
  2. #include <stdio.h>
  3.  
  4. typedef unsigned char byte;
  5.  
  6. __CONFIG(1, IESODIS & FCMDIS & RCIO);
  7. __CONFIG(2, BORDIS & BORV21 & PWRTDIS & WDTDIS);
  8. __CONFIG(3, MCLRDIS);
  9. __CONFIG(4, DEBUGDIS & LVPDIS & XINSTEN);
  10. __CONFIG(5, UNPROTECT);
  11. __CONFIG(6, WRTEN);
  12. __CONFIG(7, TRPB);
  13.  
  14. #define _XTAL_FREQ 8000000
  15. #define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000UL)))
  16. #define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000UL)))
  17.  
  18. byte rx = 0x00;
  19.  
  20. //putch implementation for printf
  21. void putch(unsigned char byte) {   
  22.     TXREG = byte;
  23.     while(TRMT == 0); //Wait while sending
  24. }
  25.  
  26. //getch implementation
  27. unsigned char getch() {
  28.     while(RCIF == 0); //Wait while receiving
  29.     return RCREG;
  30. }
  31.  
  32. void main(void) {
  33.     OSCCON = (OSCCON & 0b10001101) | 0b01110010; //Set oscillator frequency
  34.        
  35.     //All ports are output
  36.     TRISA = 0x00;
  37.     TRISB = 0x00;
  38.     TRISC = 0x00;  
  39.        
  40.     //Disable A2D
  41.     ADON = 0;
  42.    
  43.     PORTC = 0x00;
  44.     LATC = 0x00;
  45.  
  46.     while(1) {     
  47.         LATC = 0b01010101;     
  48.         __delay_ms(2000);
  49.         LATC = 0xFF;
  50.         __delay_ms(2000);      
  51.     }  
  52.    
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement