Mar 1, 2013 #1 ragav4456 Full Member level 4 Joined Aug 1, 2012 Messages 228 Helped 19 Reputation 38 Reaction score 17 Trophy points 1,308 Activity points 2,568 Hi friends I doubt in PIC uart baudrate formula calculation in Program. BRGH=1;BRG16=1; kindly send the sample code. Sample code for PIC16f877A ic UART Code: int X; /* calculate and set baud rate register */ /* for asynchronous mode */ tmp = 16UL * baud; X = (int)(FOSC/tmp) - 1; if((X>255) || (X<0)) { tmp = 64UL * baud; X = (int)(FOSC/tmp) - 1; if((X>255) || (X<0)) { return 1; /* panic - baud rate unobtainable */ } else BRGH=0; /* low baud rate */ } - - - Updated - - - how to change this code for pic16f1527 ic?
Hi friends I doubt in PIC uart baudrate formula calculation in Program. BRGH=1;BRG16=1; kindly send the sample code. Sample code for PIC16f877A ic UART Code: int X; /* calculate and set baud rate register */ /* for asynchronous mode */ tmp = 16UL * baud; X = (int)(FOSC/tmp) - 1; if((X>255) || (X<0)) { tmp = 64UL * baud; X = (int)(FOSC/tmp) - 1; if((X>255) || (X<0)) { return 1; /* panic - baud rate unobtainable */ } else BRGH=0; /* low baud rate */ } - - - Updated - - - how to change this code for pic16f1527 ic?
Mar 1, 2013 #2 jayanth.devarayanadurga Banned Joined Dec 4, 2012 Messages 4,280 Helped 822 Reputation 1,654 Reaction score 791 Trophy points 1,393 Location Bangalore, India Activity points 0 Code C - [expand]1 X = (FOSC/(16UL * baud)) - 1
Mar 1, 2013 #3 ragav4456 Full Member level 4 Joined Aug 1, 2012 Messages 228 Helped 19 Reputation 38 Reaction score 17 Trophy points 1,308 Activity points 2,568 Baudrate formula depends upon this bits BRGH=1; BRG16=1; BRG16 meaning?
Mar 1, 2013 #4 jayanth.devarayanadurga Banned Joined Dec 4, 2012 Messages 4,280 Helped 822 Reputation 1,654 Reaction score 791 Trophy points 1,393 Location Bangalore, India Activity points 0 See the images. Attachments brg16_1.jpg 219.5 KB · Views: 61 brg16_2.jpg 323.1 KB · Views: 63
Mar 2, 2013 #5 ragav4456 Full Member level 4 Joined Aug 1, 2012 Messages 228 Helped 19 Reputation 38 Reaction score 17 Trophy points 1,308 Activity points 2,568 I have doubt in 57600 is 16 bit baudrate or 8 bit baudrate.?
Mar 2, 2013 #6 jayanth.devarayanadurga Banned Joined Dec 4, 2012 Messages 4,280 Helped 822 Reputation 1,654 Reaction score 791 Trophy points 1,393 Location Bangalore, India Activity points 0 See this table. What is your Fosc? For Fosc = 20 MHz, SYNC = 0, BRGH = 1, BRG16 = 1, and baudrate 57600 bps, SPBRG value = 86. So, it is 0086. SPBRGH = 00, SPBRGL = 86. Attachments brg16.jpg 315.5 KB · Views: 68
See this table. What is your Fosc? For Fosc = 20 MHz, SYNC = 0, BRGH = 1, BRG16 = 1, and baudrate 57600 bps, SPBRG value = 86. So, it is 0086. SPBRGH = 00, SPBRGL = 86.
Mar 2, 2013 #7 ragav4456 Full Member level 4 Joined Aug 1, 2012 Messages 228 Helped 19 Reputation 38 Reaction score 17 Trophy points 1,308 Activity points 2,568 FOSC-20MHZ Baud rate-57600
Mar 2, 2013 #8 jayanth.devarayanadurga Banned Joined Dec 4, 2012 Messages 4,280 Helped 822 Reputation 1,654 Reaction score 791 Trophy points 1,393 Location Bangalore, India Activity points 0 See my last post.
Mar 2, 2013 #9 ragav4456 Full Member level 4 Joined Aug 1, 2012 Messages 228 Helped 19 Reputation 38 Reaction score 17 Trophy points 1,308 Activity points 2,568 SPBRG= 86; means UART not working. what is the reason? the first post is automatic calculation of SPBRG=X. UART output is varied. My program starting bit is 35, but output is 82 or 80 and some other else.
SPBRG= 86; means UART not working. what is the reason? the first post is automatic calculation of SPBRG=X. UART output is varied. My program starting bit is 35, but output is 82 or 80 and some other else.
Mar 2, 2013 #10 jayanth.devarayanadurga Banned Joined Dec 4, 2012 Messages 4,280 Helped 822 Reputation 1,654 Reaction score 791 Trophy points 1,393 Location Bangalore, India Activity points 0 Are you testing on Hardware or Proteus? If on Hardware maybe your PIC UART is damaged.
Mar 2, 2013 #11 ragav4456 Full Member level 4 Joined Aug 1, 2012 Messages 228 Helped 19 Reputation 38 Reaction score 17 Trophy points 1,308 Activity points 2,568 I am testing in HARDWARE.
Mar 2, 2013 #12 jayanth.devarayanadurga Banned Joined Dec 4, 2012 Messages 4,280 Helped 822 Reputation 1,654 Reaction score 791 Trophy points 1,393 Location Bangalore, India Activity points 0 Test in Proteus. if it works then the problem is in your PIC. Post your circuit, hex and cof files and I will test in Proteus.
Test in Proteus. if it works then the problem is in your PIC. Post your circuit, hex and cof files and I will test in Proteus.
Mar 2, 2013 #13 H hemporer Newbie level 6 Joined Dec 13, 2012 Messages 12 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,333 just change associate register.
Mar 5, 2013 #14 ragav4456 Full Member level 4 Joined Aug 1, 2012 Messages 228 Helped 19 Reputation 38 Reaction score 17 Trophy points 1,308 Activity points 2,568 associate register means?
Mar 5, 2013 #15 jayanth.devarayanadurga Banned Joined Dec 4, 2012 Messages 4,280 Helped 822 Reputation 1,654 Reaction score 791 Trophy points 1,393 Location Bangalore, India Activity points 0 Use UART2 instead of UART1.