xpress_embedo
Advanced Member level 4
I had purchased a development board having PIC18F4550 Development Board
And i am trying to Check the Serial Communication of my Board.
The company of my Development Board had given a sample code for Transmission of Serial 'S'.
Here is the Code
this code this working fine in my Development Board
Here is the Output on USART Terminal
Means output is working Proper.
But in this code they have put SPBRG = 0x4D; means 77(decimal)
This doesn't correspond to 9600 Baud Rate according to Datasheet
Now i write my own code in Hi-Tech C Language for Serial Communication
Based on the above code
And i am getting this Output
Which is not correct
And i am trying to Check the Serial Communication of my Board.
The company of my Development Board had given a sample code for Transmission of Serial 'S'.
Here is the Code
Code:
INCLUDE"P18F4550.INC" ;include PIC18F4580 definitions
ORG 0000H ;reset vector location
CLRF PCLATH ;clearing program counter higher bits
GOTO START ;jump to start up location defined at 30H
ORG 0030H
START ;start of program
BCF TRISC,6 ; configure RC6(TXD pin) as o/p [B]According to me this line is wrong as it is mentioned in data sheet that Rx and Tx pins TRIS value must be Set[/B]
BCF TXSTA,BRGH ; select baud-rate(9600)
BCF BAUDCON,BRG16 ; 8-bit Baud Rate Generator, SPBRG only
; value loaded corresponding to baud-rate,9600
MOVLW 0x4D
MOVWF SPBRG
BCF TXSTA,SYNC ; asynchronous mode select
BSF TXSTA,TXEN ; 8-bit transmission enable
BSF RCSTA,SPEN ; serial port enable
MOVLW 'S'
MOVWF TXREG ;transmit buffer loaded with data to be transmitted
CHECK
BTFSS TXSTA,TRMT ;wait for complete transmission and skip if done
GOTO CHECK
GOTO $ ;infinite wait
END ;end of program
this code this working fine in my Development Board
Here is the Output on USART Terminal
Means output is working Proper.
But in this code they have put SPBRG = 0x4D; means 77(decimal)
This doesn't correspond to 9600 Baud Rate according to Datasheet
Now i write my own code in Hi-Tech C Language for Serial Communication
Based on the above code
Code:
#include<htc.h>
/***************************
* Device configuration *
***************************/
#pragma config FOSC = HS // Using 20 MHz crystal with PLL
//#pragma config PLLDIV = 5 // Divide by 5 to provide the 96 MHz PLL with 4 MHz input
//#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
#pragma config IESO = OFF // Disable Oscillator Switchover mode
#pragma config PWRT = OFF // Disable Power-up timer
#pragma config BOR = OFF // Disable Brown-out reset
#pragma config WDT = OFF // Disable Watchdog timer
#pragma config MCLRE = ON // Enable MCLR Enable
#pragma config LVP = OFF // Disable low voltage ICSP
#pragma config ICPRT = OFF // Disable dedicated programming port (only on 44-pin devices)
#pragma config CP0 = OFF // Disable code protection
#define TX TRISCbits.RC6
#define RX TRISCbits.RC7
void delay_ms(unsigned int time);
void delay_us(unsigned int time);
//void SerTX(unsigned char value);
void main() @ 0x0000A0
{
TRISB = 0x00;
PORTB = 0x00;
delay_ms(1000);
PORTB = 0xFF;
delay_ms(1000);
TRISCbits.RC6 = 0;
TRISCbits.RC7 = 1; //Make Input Pin
TXSTAbits.BRGH = 0; //Select Low Speed Baud Rate
BAUDCONbits.BRG16 = 0; //Select 8-bit Baud Rate Generator Only
SPBRGH = 0x4D; //[B][I]Even when i change this value to 129 and BRGH to 1 i am getting the same result[/I][/B]
TXSTAbits.SYNC = 0; //Asynchronous Mode Selected
TXSTAbits.TXEN = 1; //8-bit Transmit mode enable
RCSTAbits.SPEN = 1; //Enable Serial Port Transmission
while(1)
{
TXREG = 'S';
while(TXSTAbits.TRMT == 0);
PORTB = 0x00;
delay_ms(1000);
PORTB = 0xFF;
}
}
/*void SerTX(unsigned char value)
{
TXREG = value;
while(TXSTAbits.TRMT == 0);
}*/
void delay_us(unsigned int time)
{
unsigned int k;
for(k=0;k<time;k++)
{
_delay(5);
}
}
void delay_ms(unsigned int time)
{
unsigned int k;
for(k=0;k<time;k++)
{
delay_us(1000);
}
}
And i am getting this Output
Which is not correct