Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Master and multi Slaves problem UART

Status
Not open for further replies.

khanh my

Junior Member level 2
Junior Member level 2
Joined
Mar 19, 2013
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,412
Hello,

I' using CCS C example of code for UART communication between one Master and one Slave. It's work well.
However, i'm trying now with two Slaves, One Master and i have problem. 2 slave data transmission on the master was wrong
I do not know how to address the slave, Who has successfully share information
code master
Code:
#include <16f887.h>


#device *=16 ADC=10
#fuses hs,nowdt,noput,noprotect,nobrownout,nolvp,nocpd,nodebug
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <stdio.h>
#include <lcd_lib_4bit.c>

unsigned int8 doc, value,value2,doc2,a;

void hienthi_lcd (void);
void main()
{
   
   delay_us(1000);

   delay_us(1000);
   set_tris_d(0x00);
   set_tris_b(0xff);

   set_tris_c(0xff);   
   set_tris_a(0xff); 
   
   lcd_init();
   
   delay_ms(500);


   while(true)
   {
        
         doc=getchar();
         delay_ms(500);
         doc2=getchar();
         hienthi_lcd ();
   }
}

void hienthi_lcd (){
         lcd_putcmd(line_1);
         lcd_putchar("MASTER");
         lcd_putcmd(line_2);
         printf(lcd_putchar,"H0=%3u H1=%3u",doc,doc2);

}

Slave 1:
Code:
#include <16f887.h>
#device adc=10
#fuses hs,nowdt,noput,noprotect,nobrownout,nolvp,nocpd,nodebug
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <stdio.h>
#include <lcd_lib_4bit.c>
#define station1 0x00
#bit RB0=0x06.0
#bit RB1=0x06.1
#bit RB2=0x06.2
#bit RB3=0x06.3
unsigned int8 doc, value,a;
void doc_xuli_adc(void);
void hienthi_lcd (void);
void khoitaouart()
{
   setup_uart(9600);
}

void main()
{
   
   delay_us(1000);
   set_tris_d(0x00);
   set_tris_b(0xff);
   set_tris_c(0xff);   
   set_tris_a(0x01);  
   setup_adc_ports(san0);
   setup_adc(adc_clock_internal); 
   lcd_init();
   delay_ms(500);

   khoitaouart();
   while(true)
   {
         doc_xuli_adc();
        
         putc(doc);
         hienthi_lcd ();

   }
}
void doc_xuli_adc () {
   set_adc_channel(0);
   delay_us(10);
   a=read_adc ();
   doc=((float)a*4.88)/10;
}

void hienthi_lcd () {
         lcd_putcmd(line_1);
         lcd_putchar("SLAVE1");
         lcd_putcmd(line_2);
         printf(lcd_putchar,"H1=%3u",doc);
}

slave 2:
Code:
#include <16f887.h>
#device adc=10
#fuses hs,nowdt,noput,noprotect,nobrownout,nolvp,nocpd,nodebug
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <stdio.h>
#include <lcd_lib_4bit.c>
#define station1 0x01
#bit RB0=0x06.0
#bit RB1=0x06.1
#bit RB2=0x06.2
#bit RB3=0x06.3
unsigned int8 doc2, value,a2;
void doc_xuli_adc2(void);
void hienthi_lcd2 (void);
void khoitaouart2()
{
   setup_uart(9600);
}

void main()
{
   
   delay_us(1000);
   set_tris_d(0x00);
   set_tris_b(0xff);
   set_tris_c(0xff);   
   set_tris_a(0x01);  
   setup_adc_ports(san0);
   setup_adc(adc_clock_internal); 
   lcd_init();
   delay_ms(500);

   khoitaouart2();
   while(true)
   {
         doc_xuli_adc2();
        
         putc(doc2);
         hienthi_lcd2 ();

   }
}
void doc_xuli_adc2 () {
   set_adc_channel(0);
   delay_us(10);
   a2=read_adc ();
   doc2=((float)a2*4.88)/10;
}

void hienthi_lcd2 () {
         lcd_putcmd(line_1);
         lcd_putchar("SLAVE1");
         lcd_putcmd(line_2);
         printf(lcd_putchar,"H1=%3u",doc2);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top