|
|
View previous topic :: View next topic |
Author |
Message |
Klas Guest
|
Counting via rs232 displaying correctly but strangely |
Posted: Wed Oct 29, 2008 2:17 am |
|
|
Hi all,
I made a code that increment an int16 variable then send it to another PIC, using Rs232, and display it in LCD there. the simulation worked but with some delay for the next decimal (supper than those I made for the first PIC).
can anybody help me to figure out the problem.
Code: |
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "flex_lcd.c"
void main() {
int a1,a2;
int16 Number;
enable_interrupts(global);
lcd_init();
lcd_putc("Running...");
Number=1;
do {
a2=(int8)(freq&0x00FF);
putc(a2);
delay_ms(500);
a1=(int8)(freq&0xFF00);
putc(a1);
Number=Number+1;
delay_ms(200);
}
while(TRUE);
} |
in the other side:
Code: |
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <stdlib.h>
#include "flex_lcd2.c"
byte lo,hi;
inth2,i=0;
int16 Number_received;
#int_RDA
void RDA_isr ( )
{
while(kbhit())
{
if(i==1)
{
hi=getc();
inth2=1;
i=0;
}
if(i==0)
{
lo=getc();
i=1;
}
}
}
void main() {
enable_interrupts(int_rda);
enable_interrupts(global);
lcd_init();
lcd_putc("Running...");
lcd_putc("\fTransmission...\n");
do
{
if(inth2)
{
freq = make16(hi,lo);
inth2=0;
}
printf(lcd_putc,"\f%Lu",freq);
}
|
thanks in advance,
Klas. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Wed Oct 29, 2008 3:39 am |
|
|
I think the 2 lines
Code: |
a2=(int8)(freq&0x00FF);
a1=(int8)(freq&0xFF00);
|
Should use Number NOT freq as freq is not defined anywhere!
You also need to shift the MSB to the right so
Code: |
a2=(int8)(Number & 0x00FF);
a1=(int8)(Number >> 8); // No need to do the &
|
I don't think the
is needed either.
It is also nicer to do
instead of
Code: |
Number = Number + 1;
|
|
|
|
Klas Guest
|
|
Posted: Wed Oct 29, 2008 6:54 am |
|
|
Wayne_ wrote: | I think the 2 lines
Code: |
a2=(int8)(freq&0x00FF);
a1=(int8)(freq&0xFF00);
|
Should use Number NOT freq as freq is not defined anywhere!
You also need to shift the MSB to the right so
Code: |
a2=(int8)(Number & 0x00FF);
a1=(int8)(Number >> 8); // No need to do the & |
I don't think the
is needed either.
It is also nicer to do
instead of
Code: |
Number = Number + 1;
|
|
Hi Wayne,
with your help the code is working fine.
I also made a another changement that made my code better, I used
the EX_SISR.c and EX_STISR.C exemples that I found in my compiler (includes bgetc(), cgetc() and bkhit()), with that buffer, I no longer have to put a delay between the sending of the int8 variables.
the main of the PIC1:
Code: |
void main() {
int a1,a2;
int16 Number;
enable_interrupts(global);
lcd_init();
lcd_putc("Running...");
Number=0;
do {
a1=(int8)(Number&0x00FF);
bputc(a1);
a2=(int8)(Number>>8);
bputc(a2);
Number++;
delay_ms(500); // without this delay the numbers will be displayed so fast that canĀ“t be seen
}
while(TRUE);
}
|
the reciver PIC:
Code: |
void main() {
enable_interrupts(int_rda);
enable_interrupts(global);
lcd_init();
lcd_putc("Running...");
do {
while(bkbhit)
{
if(i==1)
{
hi=bgetc();
inth2=1;
i=0;
}
if(i==0)
{
lo=bgetc();
i=1;
}
}
if(inth2)
{
Number = make16(hi,lo);
inth2=0;
printf(lcd_putc,"\f%Lu",Number);
}
} while (TRUE);
}
|
thank you very much Wayne,
Any remark or suggestion is welcome by anyone ! |
|
|
|
|
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
|