becool123
Newbie level 3
Hi,
I m trying to send the temperature from one PIC to an other and I am facing some problems.
I work in simulation mode,Proteus 7 for the schematic an CCS C for the C Code.
Here My Code,
the file UART.c
char RecUART (void);
void EmitUART(char c);
void InitUART(void);
/* Initialisation de l'UART */
void InitUART(void)
{
TXSTA = 0x20;
RCSTA = 0x90;
SPBRG = 0x06;
}
/* Emission d'un octet sur l'UART */
void EmitUART(char c)
{
TXREG = c;
}
/* Reception d'un Octet sur l'UART */
char RecUART (void)
{
return(RCREG);
}
the file xbee.c
#include "USART.c"
void InitXbee(void)
{
set_tris_d=0x18;
PORTD=0x05;
}
void SendByte(char c)
{
EmitUART(c);
}
char ReadByte(void)
{
return(RecUART());
}
void SendString(const unsigned char *s)
{
int i=0;
while(s!='\0')
{
/* utilisation de lcd_putch */
SendByte(s);DelayMs(100);
i++;
}
void ReadString(const unsigned char *s)
{
int i=0;
while( ReadByte()!='\0')
{
s=ReadByte()
i++;
DelayMs(100);
}
}
Emitters code
#include <16F877.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "Lcd.c"
#include "USART.c"
#device adc= 10 //sur 10 bits
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
#byte PortA = 5 // adresse du PORT A
#byte PortB = 6 // adresse du PORT B
long tension;
float val;
char ordre[32];
void main() {
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_a(0b00001111);
setup_adc_ports(A_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
InitUART();
InitXbee();
while(1)
{
delay_ms(100);
tension = read_adc();
temp=((float)tension/1023)*5*100;
sprintf(ordre,"%f",temp)//pour convertir de float à string
SendString(ordre);
}
}
receiver code
#include <16F877.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOPROTECT, PUT, NOLVP
#use rs232 (baud = 9600, xmit = PIN_C6, rcv = PIN_C7)
#include "Lcd.c"
#include "Lcd.c"
#include "USART.c"
void main()
{
char ordre[32];
lcd_init();
InitUART();
InitXbee();
while(1 ){
ReadString(ordre);
printf(lcd_putc,"\f%f C",ordre);
}
}
In the attachement the schemetic file,
Thanks
I m trying to send the temperature from one PIC to an other and I am facing some problems.
I work in simulation mode,Proteus 7 for the schematic an CCS C for the C Code.
Here My Code,
the file UART.c
char RecUART (void);
void EmitUART(char c);
void InitUART(void);
/* Initialisation de l'UART */
void InitUART(void)
{
TXSTA = 0x20;
RCSTA = 0x90;
SPBRG = 0x06;
}
/* Emission d'un octet sur l'UART */
void EmitUART(char c)
{
TXREG = c;
}
/* Reception d'un Octet sur l'UART */
char RecUART (void)
{
return(RCREG);
}
the file xbee.c
#include "USART.c"
void InitXbee(void)
{
set_tris_d=0x18;
PORTD=0x05;
}
void SendByte(char c)
{
EmitUART(c);
}
char ReadByte(void)
{
return(RecUART());
}
void SendString(const unsigned char *s)
{
int i=0;
while(s!='\0')
{
/* utilisation de lcd_putch */
SendByte(s);DelayMs(100);
i++;
}
void ReadString(const unsigned char *s)
{
int i=0;
while( ReadByte()!='\0')
{
s=ReadByte()
i++;
DelayMs(100);
}
}
Emitters code
#include <16F877.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "Lcd.c"
#include "USART.c"
#device adc= 10 //sur 10 bits
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
#byte PortA = 5 // adresse du PORT A
#byte PortB = 6 // adresse du PORT B
long tension;
float val;
char ordre[32];
void main() {
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_a(0b00001111);
setup_adc_ports(A_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
InitUART();
InitXbee();
while(1)
{
delay_ms(100);
tension = read_adc();
temp=((float)tension/1023)*5*100;
sprintf(ordre,"%f",temp)//pour convertir de float à string
SendString(ordre);
}
}
receiver code
#include <16F877.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOPROTECT, PUT, NOLVP
#use rs232 (baud = 9600, xmit = PIN_C6, rcv = PIN_C7)
#include "Lcd.c"
#include "Lcd.c"
#include "USART.c"
void main()
{
char ordre[32];
lcd_init();
InitUART();
InitXbee();
while(1 ){
ReadString(ordre);
printf(lcd_putc,"\f%f C",ordre);
}
}
In the attachement the schemetic file,
Thanks