View previous topic :: View next topic |
Author |
Message |
fsven
Joined: 18 Sep 2008 Posts: 3
|
Binary to ASCII-Lcd problem |
Posted: Mon Sep 22, 2008 3:46 pm |
|
|
HI'
I'm a newbie in pic programming. Right now I'm developing a system that can convert binary input to ASCII character. Here's my coding:
Quote: | #include <16f877a.h>
#use delay (clock = 40000000)
#fuses hs,noprotect,nowdt,nolvp
#BYTE PORTA=5
#BYTE PORTB=6
#BYTE PORTC=7
#include <flex_lcd.c>
#include <kbd44.c>
void main()
{
char n;
set_tris_a (0);
set_tris_b (0);
set_tris_c (0xff);
lcd_init();
lcd_putc("\fReady...\n");
while(TRUE)
{
switch( PORTC )
{
case 0x00000001: lcd_putc("A\n"); break;
case 0b00000011: lcd_putc("X\n"); break;
}
}
}
|
My problem is: when 2nd input trigger, the LCD overwrite onto 1st character. It cannot display after the 1st character and continuously when another input trigger. Plz help me.
TQ |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 22, 2008 4:14 pm |
|
|
Quote: | #include <16f877a.h>
#use delay (clock = 40000000)
#fuses hs,noprotect,nowdt,nolvp
#BYTE PORTA=5
#BYTE PORTB=6
#BYTE PORTC=7
#include <flex_lcd.c>
#include <kbd44.c>
void main()
{
char n;
set_tris_a (0);
set_tris_b (0);
set_tris_c (0xff);
|
This is not a real program. The 16F877A can't run faster than 20 MHz.
You have the #use delay() statement set for 40 MHz.
Also, my suggestion is to let the compiler handle the TRIS.
Use CCS i/o functions. Don't read/write directly to registers.
If you want to read port C, then do this:
Code: |
int8 value;
value = input_c();
switch(value)
{
|
Quote: | My problem is: when 2nd input trigger, the LCD overwrite onto 1st character |
Look at the lcd_putc() function in the Flex driver:
Code: |
case '\n':
[b]lcd_gotoxy(1,2); [/b]
break; |
A newline causes it to set the cursor to the first position in line 2,
on a 16x2 LCD. Everytime your code has a newline (\n), that's
where the next LCD text will go. That's why it's overwriting. |
|
|
Guest
|
|
Posted: Tue Sep 23, 2008 9:11 am |
|
|
Quote: | case '\n':
lcd_gotoxy(1,2);
break;
A newline causes it to set the cursor to the first position in line 2,
on a 16x2 LCD. Everytime your code has a newline (\n), that's
where the next LCD text will go. That's why it's overwriting. |
Thanks for the info. I want to make the LCD display character without overwriting previous input character. Can anybody help me? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Sep 23, 2008 2:12 pm |
|
|
As explained, the newline character is your problem.
Solution:
Don't send '\n'... |
|
|
Guest
|
|
Posted: Tue Sep 23, 2008 3:12 pm |
|
|
When \n removed, the character repeated and fill entire LCD. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Sep 23, 2008 3:28 pm |
|
|
Solving one problem often shows you there is another problem waiting to be solved....
So now you have fixed the character being overwritten have another look at your code. You are reading PORTC, display the value and then start all over again. In other words: you are reading PORTC as fast as the processor can handle it. If you want the processor to wait for something to happen you will have to implement code for this.
You haven't told us what is connected to PORTC. Is it a keyboard? (you are including kbd44.c) |
|
|
fsven
Joined: 18 Sep 2008 Posts: 3
|
|
Posted: Tue Sep 23, 2008 4:51 pm |
|
|
PORTC connected to switch (binary selector) and push button. Below the image.
|
|
|
|