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

Binary to ASCII-Lcd problem

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



Joined: 18 Sep 2008
Posts: 3

View user's profile Send private message

Binary to ASCII-Lcd problem
PostPosted: Mon Sep 22, 2008 3:46 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 22, 2008 4:14 pm     Reply with quote

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








PostPosted: Tue Sep 23, 2008 9:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 23, 2008 2:12 pm     Reply with quote

As explained, the newline character is your problem.
Solution:
Don't send '\n'...
Guest








PostPosted: Tue Sep 23, 2008 3:12 pm     Reply with quote

When \n removed, the character repeated and fill entire LCD.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 23, 2008 3:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 23, 2008 4:51 pm     Reply with quote

PORTC connected to switch (binary selector) and push button. Below the image.
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