Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1.  
  2. #define _XTAL_FREQ 8000000
  3.  
  4. #include <xc.h>
  5. #include "_LCD_H.h"
  6.  
  7. #pragma config OSC = IRCIO, WDTEN = OFF
  8. #pragma config MCLRE = ON // MCLR Pin Enable bit (Enabled) turn off when on the robot
  9.  
  10. char getCharSerial(void);
  11. void sendCharSerial(char charToSend);
  12. void Serial2String(char *string);
  13.  
  14. volatile char string_b[16];
  15.  
  16. void main(void) {
  17. int i;
  18.  
  19. TRISC = 0b11000000; //set data direction registers
  20. //both need to be 1 even though RC6
  21. //is an output, check the datasheet!
  22.  
  23. TRISB = 0b00000000;
  24. PORTB = 0;
  25.  
  26. OSCCON = 0b11110010; //internal oscillator, 8MHz
  27. while (!OSCCONbits.IOFS);
  28.  
  29. SPBRG = 204; //set baud rate to 9600
  30. SPBRGH = 0;
  31.  
  32. BAUDCONbits.BRG16 = 1; //set baud rate scaling to 16 bit mode
  33. TXSTAbits.BRGH = 1; //high baud rate select bit
  34. RCSTAbits.SPEN = 1; //enable serial port, other settings default
  35. RCSTAbits.CREN = 1; //continous receive mode
  36.  
  37. LCD_Init();
  38.  
  39. while (1) {
  40. Serial2String(string_b);
  41. LCD_String(string_b);
  42. }
  43. }
  44.  
  45. char getCharSerial(void) {
  46. while (!PIR1bits.RCIF);
  47. return RCREG;
  48. }
  49.  
  50. void Serial2String(char *string) {
  51. do {
  52. *string++ = getCharSerial();
  53. } while(*string != '\0');
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement