Slave to Master Synchronous USART

General discussion on mikroElektronika website & forums.
Post Reply
Author
Message
wakhyudwi
Posts: 1
Joined: 10 Nov 2014 03:31

Slave to Master Synchronous USART

#1 Post by wakhyudwi » 10 Nov 2014 03:46

Can anybody help me please?

I have two listing program as shown below, slave mcu has to send data to master MCU, but i get nothing.

///1. slave
void main() {
char a=0;
RCSTA.SPEN=1;
TXSTA.SYNC=1;
TXSTA.CSRC=0;
RCSTA.CREN=0;
RCSTA.SREN=0;
TXSTA.TXEN=1;
for(;;)
{
TXREG=a;
while(!PIR1.TXIF)
{}
a++;
delay_ms(500);
}
}


///2. master
// LCD connection
sbit LCD_RS at RB0_bit; //
sbit LCD_EN at RB2_bit; //
sbit LCD_D4 at RB4_bit; //
sbit LCD_D5 at RB5_bit; //
sbit LCD_D6 at RB6_bit; //
sbit LCD_D7 at RB7_bit; //
sbit LCD_RS_Direction at TRISB0_bit; //
sbit LCD_EN_Direction at TRISB2_bit; //
sbit LCD_D4_Direction at TRISB4_bit; //
sbit LCD_D5_Direction at TRISB5_bit; //
sbit LCD_D6_Direction at TRISB6_bit; //
sbit LCD_D7_Direction at TRISB7_bit; //
// end LCD connection
char a;
void interrupt()
{
if(PIR1.RCIF)
{
a=RCREG;
}
}
void PrintToDisplay(char x, char y, float in1)
{
char ch;
int tint;
tint=(int)in1;
ch=tint/100;
Lcd_Chr(x,y,ch+48);
ch=(tint%100)/10;
Lcd_Chr_Cp(ch+48);
ch=(tint%100)%10;
Lcd_Chr_Cp(ch+48);
Delay_Ms(10);
}

void main() {
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
SPBRG=39;
TXSTA.SYNC=1;
RCSTA.SPEN=1;
TXSTA.CSRC=1;
RCSTA.CREN=0;
RCSTA.SREN=0;
PIE1.RCIE=1;
INTCON.PEIE=1;
INTCON.GIE=1;
RCSTA.CREN=1;
for(;;)
{
Lcd_Out(1,1,"Data In");
PrintToDisplay(2,1,a);
}
}

Thanks for help

Post Reply

Return to “Website & Forums General Discussion”