![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
elekeng
Joined: 30 Jun 2012 Posts: 3
|
using together problem rs232 and lcd |
Posted: Sat Jun 30, 2012 5:33 am |
|
|
Hi programmers!
I read many answers about this problem but no answer make me be sure enough.
the goal is to get a character via uart and write to the lcd.
when i am using just uart interrupt it's ok.But if using #int_rda and lcd,code enters interrupt only once time and never enters again.
I guess there is a mismatch between #int_rda and lcd_init();
how can i overcome this problem!?
the code is here,
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected
#use delay(clock=4000000)
#use rs232(baud=1500,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stop=1)
#include <stdio.h>
#define led pin_D2
#define buton1 pin_A3
#define buton2 pin_A4
#define buton3 pin_A5
#define buton4 pin_A2
#define use_portb_lcd TRUE
#include <lcd420.c>
char klavye[80],t;
int i=0;
#int_rda
void serihaberlesme_kesmesi()
{
disable_interrupts(int_rda);
t=getc();
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init();
lcd_send_byte(0,0x0d);
printf(lcd_putc,"\f program start");
delay_ms(1000);
enable_interrupts(GLOBAL);
enable_interrupts(int_rda);
while(1)
{
enable_interrupts(int_rda);
output_low(pin_c2);
output_high(pin_c3); (dont consider this pins)
printf(lcd_putc,"\fgelen:%c",t);
delay_ms(1000);
}
and sometime lcd shows character of ||. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sat Jun 30, 2012 6:14 am |
|
|
comments..
1) 1500 baud is rather uncommon...are you sure you want this speed ?
2) always add 'errors' to the use rs232(....) line.Without it the Hardware UART will be stopped after 2-3 characters being received.
3) get rid of the disable interrupt inside the ISR.NOT needed, compiler handles it automatically.
4) you should set PUT in the fuses.It helps the PIC get going in a known,orderly fashion.
hth jay |
|
![](templates/subSilver/images/spacer.gif) |
elekeng
Joined: 30 Jun 2012 Posts: 3
|
|
Posted: Sat Jun 30, 2012 6:30 am |
|
|
i tested communicatin with 1500 baud rate it's ok because i realized it one-way comunication.only when I want to use LCD this problem appears.
also i added 'errors' it doesnt matter.
now code gets into the interrupts but still it is not processing getc().
the problem is not about speed and anything else only with LCD functions. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Sat Jun 30, 2012 7:48 am |
|
|
1) Learn to use the code buttons.......
2) _Always_ have ERRORS. This is _essential_, unless you handle UART errors yourself. Without it the UART at some point _will_ go wrong.
3) Problem with setup_spi(SPI_SS_DISABLED); - this is a fault with the Wizard. Correct syntax is setup_spi(FALSE); - this will cause problems with some of the portC pins - one is C3, which you are trying to use.
4) Repeat of Temtronic's comment to get rid of the disable_interrupts in the ISR. Also get rid of the enable in the while loop.
5) As it stands, how would you know what is happening?. The code will keep printing the last character even if a new one has not been received.
6) _Delay_ for a little before initialising the LCD. Some do need a little more time than the default allowed by the driver, to work 'right'.
7) Repeat of Temtronic's comment about 1500 being an off baud rate. Are you _sure_ this is what the other end is actually sending?. Some hardware will have significant trouble generating this rate. Some of the USB-UART adapters, will not actually support this rate, which would then lead to data corruption.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
elekeng
Joined: 30 Jun 2012 Posts: 3
|
|
Posted: Sat Jun 30, 2012 8:30 am |
|
|
Firstly let me give you more information my project.
I am making a robot full controlled by remote control.there is due-line communication between robot and remote control. So the remote control has 4 buttons to give the directions to the robot. Also robot measures temperature and send to the remote control.
And by now everything is ok. I can drive the robot perfectly with this code:
Remote control:
Code: |
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected
#use delay(clock=4000000)
#use rs232(baud=1500,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stop=1)
#include <stdio.h>
#define led pin_D2
#define buton1 pin_A3
#define buton2 pin_A4
#define buton3 pin_A5
#define buton4 pin_A2
#define use_portb_lcd TRUE
#include <lcd.c>
char klavye[80],t='w';
int i=0;
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init();
lcd_send_byte(0,0x0d);
printf(lcd_putc,"\f program start");
delay_ms(1000);
enable_interrupts(GLOBAL);
enable_interrupts(int_rda);
while(1)
{
output_low(pin_c2);
output_high(pin_c3);
while(input(buton1))
{
printf(lcd_putc,"\f Arac ileri");
delay_ms(1000);
devam:
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0xff);
putc(0xff);
putc(0xff);
putc(0xff);
putc(0xff);
putc('x');
putc('x');
putc('x');
putc('x');
putc('x');
putc('i');
if(input(buton1))
goto devam;
}
delay_ms(100);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0xff);
putc(0xff);
putc(0xff);
putc(0xff);
putc(0xff);
putc('x');
putc('x');
putc('x');
putc('x');
putc('x');
putc('e');
while(input(buton2))
{
printf(lcd_putc,"\f Arac geri");
delay_ms(1000);
devam1:
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0x00);
putc(0xff);
putc(0xff);
putc(0xff);
putc(0xff);
putc(0xff);
putc('x');
putc('x');
putc('x');
putc('x');
putc('x');
putc('g');
if(input(buton2))
goto devam1;
}
}
}
|
ROBOT:
Code: |
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected
#use delay(clock=4000000)
#use rs232(baud=1500,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stop=1)
#include <stdio.h>
char t;
int y=0;
#int_rda
void serihaberlesme_kesmesi()
{
disable_interrupts(int_rda);
if(getc()=='x')
{
t=getc();
}
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(GLOBAL);
output_high(pin_D6);
output_high(pin_D2);
delay_ms(1000);
output_low(pin_D6);
output_low(pin_D2);
bass:
output_low(pin_D6); /*led pasif*/
output_low(pin_D2); /*led pasif*/
output_high(pin_D3); /*verici devre dısı*/
output_low(pin_C4); /*alıcı devrede*/
enable_interrupts(int_rda);
output_low(pin_B6);
output_low(pin_B5);
output_low(pin_B4);
output_low(pin_B3);
output_low(pin_B2);
output_low(pin_B1);
output_low(pin_B0);
output_low(pin_E2);
output_low(pin_C0);
output_low(pin_C1);
output_low(pin_C2);
output_low(pin_C3);
output_low(pin_D0);
output_low(pin_D1);
while(t=='i')
{
output_high(pin_D6);
/*ILERI GITME MODU*/
enable_interrupts(int_rda);
/*MOTOR SURUCU 1 */
output_high(pin_B6); /*kopru A aktif*/
output_high(pin_B0); /*kopru B aktif*/
output_high(pin_B1); /*lojik giris*/
output_high(pin_B3); /* A koprusu girisleri*/
output_low(pin_B2); /* A koprusu girisleri*/
output_high(pin_B5); /* B koprusu girisleri*/
output_low(pin_B4); /* B koprusu girisleri*/
/*MOTOR SURUCU 2 */
output_high(pin_E2); /*kopru A aktif*/
output_high(pin_D1); /*kopru B aktif*/
output_high(pin_D0); /*lojik giris*/
output_high(pin_C2); /* A koprusu girisleri*/
output_low(pin_C3); /* A koprusu girisleri*/
output_high(pin_C0); /* B koprusu girisleri*/
output_low(pin_C1); /* B koprusu girisleri*/
}
while(t=='g')
{
output_high(pin_D2);
/*GERI GITME MODU*/
enable_interrupts(int_rda);
/*MOTOR SURUCU 1 */
output_high(pin_B6); /*kopru A aktif*/
output_high(pin_B0); /*kopru B aktif*/
output_high(pin_B1); /*lojik giris*/
output_low(pin_B3); /* A koprusu girisleri*/
output_high(pin_B2); /* A koprusu girisleri*/
output_low(pin_B5); /* B koprusu girisleri*/
output_high(pin_B4); /* B koprusu girisleri*/
/*MOTOR SURUCU 2 */
output_high(pin_E2); /*kopru A aktif*/
output_high(pin_D1); /*kopru B aktif*/
output_high(pin_D0); /*lojik giris*/
output_low(pin_C2); /* A koprusu girisleri*/
output_high(pin_C3); /* A koprusu girisleri*/
output_low(pin_C0); /* B koprusu girisleri*/
output_high(pin_C1); /* B koprusu girisleri*/
}
while(t=='l')
{
output_high(pin_D2);
/*SOL GITME MODU*/
enable_interrupts(int_rda);
/*MOTOR SURUCU 1 */
output_high(pin_B6); /*kopru A aktif*/
output_high(pin_B0); /*kopru B aktif*/
output_high(pin_B1); /*lojik giris*/
output_low(pin_B3); /* A koprusu girisleri*/
output_high(pin_B2); /* A koprusu girisleri*/
output_high(pin_B5); /* B koprusu girisleri*/
output_low(pin_B4); /* B koprusu girisleri*/
/*MOTOR SURUCU 2 */
output_high(pin_E2); /*kopru A aktif*/
output_high(pin_D1); /*kopru B aktif*/
output_high(pin_D0); /*lojik giris*/
output_low(pin_C2); /* A koprusu girisleri*/
output_high(pin_C3); /* A koprusu girisleri*/
output_high(pin_C0); /* B koprusu girisleri*/
output_low(pin_C1); /* B koprusu girisleri*/
}
while(t=='r')
{
output_high(pin_D2);
/*SAG GITME MODU*/
enable_interrupts(int_rda);
/*MOTOR SURUCU 1 */
output_high(pin_B6); /*kopru A aktif*/
output_high(pin_B0); /*kopru B aktif*/
output_high(pin_B1); /*lojik giris*/
output_high(pin_B3); /* A koprusu girisleri*/
output_low(pin_B2); /* A koprusu girisleri*/
output_low(pin_B5); /* B koprusu girisleri*/
output_high(pin_B4); /* B koprusu girisleri*/
/*MOTOR SURUCU 2 */
output_high(pin_E2); /*kopru A aktif*/
output_high(pin_D1); /*kopru B aktif*/
output_high(pin_D0); /*lojik giris*/
output_high(pin_C2); /* A koprusu girisleri*/
output_low(pin_C3); /* A koprusu girisleri*/
output_low(pin_C0); /* B koprusu girisleri*/
output_high(pin_C1); /* B koprusu girisleri*/
}
}
|
Now the next step is getting data from the robot to the remote contol.
So the problem appears this step. I have changed baud rate to 300 but it didnt work! Also I added 'ERRORS'.
I am suspected about hardware and I made the new receiver without LCD.
Yes it works, so robot sends the datas correctly but I am not getting it with using LCD. ![Shocked](images/smiles/icon_eek.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|