|
|
View previous topic :: View next topic |
Author |
Message |
arunkish
Joined: 23 Dec 2008 Posts: 83
|
Having a little Strange Problem with UART |
Posted: Thu Jun 30, 2011 3:56 am |
|
|
Dear All
I have a HMI TFT that can be controlled using MCU's via UART and also PC.
I wrote a little program in Visual basic to print a text and when tested it works fine. The code is below.
Code: |
MSComm1.Output = Chr(&HAA) & Chr(&H55) ' Command
MSComm1.Output = Chr(&H2) & Chr(&HCB) & Chr(&H1) & Chr(&H91) ' Position
MSComm1.Output = "HELLO"
MSComm1.Output = Chr(&HCC) & Chr(&H33) & Chr(&HC3) & Chr(&H3C) ' End Termination
|
However when I try the same with PIC controller, it does not work. I tried the same in many ways and I am confused. I check the output of the PIC in a PC and that was also ok. I really do not know how to sort it out. Here is the code I use for the MCU.
Code: |
#include <18F4620.H>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#fuses HS,PROTECT,PUT,NOBROWNOUT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=115200,xmit=PIN_C6,rcv=PIN_C7)
#byte TRISC = 0xf94
#byte PORTC = 0xf82
#INT_RDA
void serial_reciv_int(void)
{
}
void main(void)
{
int i;
set_tris_c(0x00);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);
delay_ms(1000);
putc(0xAA);
putc(0x55);
putc(0x00);
putc(0x80);
putc(0x00);
putc(0x30);
printf("hello");
putc(0xCC);
putc(0x33);
putc(0xC3);
putc(0x3C);
//printf("\xAA\x55\x00\x80\x00\x30HELLO\xCC\x33\xC3\x3C");
while(1)
{
delay_ms(2000);
}
}
|
Kindly suggest me what would be the mistake. Should I increase the crystal frequency???
Regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Thu Jun 30, 2011 5:14 am |
|
|
Quick comments.
Good news is that at least the PC program works !
1) the VB program may be sending cr/lf after each line sent to the serial port.
IE: MSComm1.Output = Chr(&HAA) & Chr(&H55) ' Command
may actually be sending AA;55;0C;0A
2) you need a MAX232 or equal chip between the PIC and the LCD. This is required to invert the logic level of the data.
3) you _must_ add 'errors' to the use rs232(....) function.
4) you probably do not require the 10 second delay.
5) disable the interrupts as you're not using them.
6) get rid of the set_tris... functions. Unless you're an expert it'll cause you problems. Let the compiler automatically handle the I/O ports for you!
7) for this small program you do not need to include all those .h files !
Start small, make backups and have fun ! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 30, 2011 2:12 pm |
|
|
You must get the character to clear the RDA interrupt.
Even if you don't use the character, you must still read it from the UART.
Example:
Code: | #INT_RDA
void serial_reciv_int(void)
{
char c;
c = getc();
}
|
|
|
|
arunkish
Joined: 23 Dec 2008 Posts: 83
|
|
Posted: Thu Jun 30, 2011 9:18 pm |
|
|
Dear PCM Programmer,
Thank you very much for your advice. I followed all the steps that you have mentioned. But Still I did not make it work. Here is the modified code.... This command should actually clear the screen. As usual works with VB serial out, but not responding to MCU
Code: |
#include <18F4620.H>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#fuses HS,PUT,NOBROWNOUT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600,PARITY=N,BITS =8,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#byte TRISC = 0xf94
#byte PORTC = 0xf82
#byte TRISD = 0xf95
#byte PORTD = 0xf83
#byte TRISB = 0xf93
#byte PORTB = 0xf81
#INT_RDA
void serial_reciv_int(void)
{
char c;
c = getc();
}
void main(void)
{
//set_tris_d(0x00);
//set_tris_b(0x00);
//set_tris_c(0x00);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
delay_ms(3000);
delay_ms(3000);
delay_ms(3000);
clear_interrupt(INT_RDA);
putc(0xAA);
putc(0x52);
putc(0xCC);
putc(0x33);
putc(0xC3);
putc(0x3C);
putc(0x0C);
putc(0x0A);
//printf("\xAA\x55\x00\x80\x00\x30HELLO\xCC\x33\xC3\x3C");
//printf("\xCC\x33\xC3\x3C");
while(1)
{
delay_ms(500);
}
}
|
Here is the link for the datasheet of the TFT. Please advice where I am wrong. I have used MAX232 chip. I monitored the output of the PIC in a PC and it transmits the data, I am really confused why the TFT is not accepting it.
http://www.dwin.com.cn/en/Upfile/DMG80480S050_01W_DataSheet.pdf
Thanks for your time |
|
|
|
|
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
|