CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RS-232 by 16F873

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FRANCESC
Guest







RS-232 by 16F873
PostPosted: Sun Jul 06, 2003 2:08 pm     Reply with quote

Hi all
I need comunicate 2 PICS 16F873 by RS-232.
I write two independent programs.
Send Program:
include <16f873.h>
#use delay(clock=4000000,RESTART_WDT)
#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7,RESTART_WDT)
#use I2C(MASTER,SDA=PIN_B6,SCL=PIN_B7,SLOW,RESTART_WDT)
#use fast_io(A)
#use fast_io(B)
#define AnalogWrite 0x90
#define AnalogRead 0x91
#define Reg_Control_Inc 0x04
LONG INT K1,K2,K3,K0;

void read_8591(void)
{
i2c_start();
i2c_write(AnalogWrite);
i2c_write(Reg_Control_Inc);
}
Main()
{
while(1)
{
read_8591();
i2c_start();
i2c_write(AnalogRead);
K0=i2c_read();
K1=i2c_read();
K2=i2c_read();
K3=i2c_read(0);
i2c_stop();
puts(K0);
delay_ms(200);
puts(K1);
delay_ms(200);
puts(K2);
delay_ms(200);
puts(K3);
delay_ms(200);
}
}

Receive program
#include <16f873.h>
#use delay(clock=4000000,RESTART_WDT)
#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7,RESTART_WDT)
#use fast_io(A)
#use fast_io(B)
#include <lcd2.c>
LONG INT K,K1,K2,K3,K0;

main()
{
lcd_init();
K=K0;
lcd_gotoxy(1,1);
lcd_putc(K\%10);
K=K1;
lcd_gotoxy(5,1);
lcd_putc(K\%10);
K=K2;
lcd_gotoxy(1,2);
lcd_putc(K\%10);
K=K3;
lcd_gotoxy(5,2);
lcd_putc(K\%10);

The program not run and display not read nothing.
Please Help me ???
Many thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515751
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

Re: RS-232 by 16F873
PostPosted: Sun Jul 06, 2003 4:44 pm     Reply with quote

<font face="Courier New" size=-1>:=Hi all
:=I need comunicate 2 PICS 16F873 by RS-232.
:=I write two independent programs.
:=Send Program:
:=include <16f873.h>
:=#use delay(clock=4000000,RESTART_WDT)
:=#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7,RESTART_WDT)
:=#use I2C(MASTER,SDA=PIN_B6,SCL=PIN_B7,SLOW,RESTART_WDT)
:=#use fast_io(A)
:=#use fast_io(B)
:=#define AnalogWrite 0x90
:=#define AnalogRead 0x91
:=#define Reg_Control_Inc 0x04
:=LONG INT K1,K2,K3,K0;
:=
:=void read_8591(void)
:={
:= i2c_start();
:= i2c_write(AnalogWrite);
:= i2c_write(Reg_Control_Inc);
:=}
:=Main()
:={
:= while(1)
:= {
:= read_8591();
:= i2c_start();
:= i2c_write(AnalogRead);
:= K0=i2c_read();
:= K1=i2c_read();
:= K2=i2c_read();
:= K3=i2c_read(0);
:= i2c_stop();
:= puts(K0);
:= delay_ms(200);
:= puts(K1);
:= delay_ms(200);
:= puts(K2);
:= delay_ms(200);
:= puts(K3);
:= delay_ms(200);
:=}
:=}
:=
:=Receive program
:=#include <16f873.h>
:=#use delay(clock=4000000,RESTART_WDT)
:=#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7,RESTART_WDT)
:=#use fast_io(A)
:=#use fast_io(B)
:=#include <lcd2.c>
:=LONG INT K,K1,K2,K3,K0;
:=
:=main()
:={
:= lcd_init();
:=K=K0;
:=lcd_gotoxy(1,1);
:=lcd_putc(K\%10);
:=K=K1;
:=lcd_gotoxy(5,1);
:=lcd_putc(K\%10);
:=K=K2;
:=lcd_gotoxy(1,2);
:=lcd_putc(K\%10);
:=K=K3;
:=lcd_gotoxy(5,2);
:=lcd_putc(K\%10);
:=
:=The program not run and display not read nothing.
:=Please Help me ???
:=Many thanks

There are a few problems that I can see.
Disable watchdog until last stage of code development, it can cause lots of problems during debugging.
You need a line like the following on both PICs:
#fuses HS,NOWDT,NOLVP,PUT

Need to #include lcd.c on the receiver.
With #use fast_io you need to set the tris manually.
There's nowhere in the receiver code where the incoming data bytes are handled. See recent posts about receiving a byte and putting it into a circular buffer in the interrupt service routine.

Also break the problem into manageable pieces, eg comment out the i2c and lcd code, instead use leds on a port of the receiver (or a second rs232 port for printf debugging) to prove the link.
Regards
Kenny </font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515753
SebDey
Guest







Re: RS-232 by 16F873
PostPosted: Mon Jul 07, 2003 12:57 am     Reply with quote

:=<font face="Courier New" size=-1>:=Hi all
:=:=I need comunicate 2 PICS 16F873 by RS-232.
:=:=I write two independent programs.
:=:=Send Program:
:=:=include <16f873.h>
:=:=#use delay(clock=4000000,RESTART_WDT)
:=:=#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7,RESTART_WDT)
:=:=#use I2C(MASTER,SDA=PIN_B6,SCL=PIN_B7,SLOW,RESTART_WDT)
:=:=#use fast_io(A)
:=:=#use fast_io(B)
:=:=#define AnalogWrite 0x90
:=:=#define AnalogRead 0x91
:=:=#define Reg_Control_Inc 0x04
:=:=LONG INT K1,K2,K3,K0;
:=:=
:=:=void read_8591(void)
:=:={
:=:= i2c_start();
:=:= i2c_write(AnalogWrite);
:=:= i2c_write(Reg_Control_Inc);
:=:=}
:=:=Main()
:=:={
:=:= while(1)
:=:= {
:=:= read_8591();
:=:= i2c_start();
:=:= i2c_write(AnalogRead);
:=:= K0=i2c_read();
:=:= K1=i2c_read();
:=:= K2=i2c_read();
:=:= K3=i2c_read(0);
:=:= i2c_stop();
:=:= puts(K0);
:=:= delay_ms(200);
:=:= puts(K1);
:=:= delay_ms(200);
:=:= puts(K2);
:=:= delay_ms(200);
:=:= puts(K3);
:=:= delay_ms(200);
:=:=}
:=:=}
:=:=
:=:=Receive program
:=:=#include <16f873.h>
:=:=#use delay(clock=4000000,RESTART_WDT)
:=:=#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_C6,RCV=PIN_C7,RESTART_WDT)
:=:=#use fast_io(A)
:=:=#use fast_io(B)
:=:=#include <lcd2.c>
:=:=LONG INT K,K1,K2,K3,K0;
:=:=
:=:=main()
:=:={
:=:= lcd_init();
:=:=K=K0;
:=:=lcd_gotoxy(1,1);
:=:=lcd_putc(K\%10);
:=:=K=K1;
:=:=lcd_gotoxy(5,1);
:=:=lcd_putc(K\%10);
:=:=K=K2;
:=:=lcd_gotoxy(1,2);
:=:=lcd_putc(K\%10);
:=:=K=K3;
:=:=lcd_gotoxy(5,2);
:=:=lcd_putc(K\%10);
:=:=
:=:=The program not run and display not read nothing.
:=:=Please Help me ???
:=:=Many thanks
:=
:=There are a few problems that I can see.
:=Disable watchdog until last stage of code development, it can cause lots of problems during debugging.
:=You need a line like the following on both PICs:
:=#fuses HS,NOWDT,NOLVP,PUT
:=
:=Need to #include lcd.c on the receiver.
:=With #use fast_io you need to set the tris manually.
:=There's nowhere in the receiver code where the incoming data bytes are handled. See recent posts about receiving a byte and putting it into a circular buffer in the interrupt service routine.
:=
:=Also break the problem into manageable pieces, eg comment out the i2c and lcd code, instead use leds on a port of the receiver (or a second rs232 port for printf debugging) to prove the link.
:=Regards
:=Kenny </font>

Hello,
perhaps a silly answer, but where are the getc() in your receive program ???
I think that by writing K=K0...K=K1...K=K2 etc you intend to do K=getc(), where the value returned by getc() will be the last character (K0, K1, or Kx) you sent from the other pic.

Hope I didn't misunderstood your code or question...
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515757
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group