|
|
View previous topic :: View next topic |
Author |
Message |
RAHUL Guest
|
8 BIT INPUT WITH PIC 16F874 AND DISPLAY ON LCD |
Posted: Sat Mar 18, 2006 9:43 am |
|
|
how do i take 8 bit parallel input with pic16f874??
I need to display this input as integer on 2*16 hitachi hd44780 LCD
(I used up port C of pic to connect to LCD.)
here is PIC datacheet:http://ww1.microchip.com/downloads/en/devicedoc/30292c.pdf
Kindly help |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 18, 2006 11:52 am |
|
|
The program below will read 8 bits of parallel data on Port B,
and display it on the LCD.
Code: |
#include <16F874.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <lcd.c>
//=======================
void main()
{
int8 value;
port_b_pullups(TRUE);
lcd_init();
while(1)
{
value = input_b();
printf(lcd_putc, "\f%x", value);
delay_ms(1000);
}
} |
|
|
|
RAHUL Guest
|
ONE probem |
Posted: Sat Mar 18, 2006 3:50 pm |
|
|
The code works fine but it shows hex instead of decimal.It shows 0f,ff,0a etc.I want to display"Grain depth:"follwed by interger value.Pls help. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Mar 18, 2006 3:56 pm |
|
|
Look up printf in your help file. It show the various format specifiers. |
|
|
RAHUL Guest
|
urgent |
Posted: Sat Mar 18, 2006 6:45 pm |
|
|
#include <16F874.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <lcd.c>
//=======================
void main()
{
int8 value;
port_b_pullups(TRUE);
lcd_init();
while(1)
{
value = input_b();
printf(lcd_putc, "\f%x", value); --
delay_ms(1000);
}
}
1)HOW DO I ADD MESSAGE BEFORE THIS \f%x?? I ADDED A MESSAGE THE LCD SHOWED IT REPEATEDLY....PLS HELP
2)How do i convert first 7 bits of input to Integer??and use eighth bit as an error bit??? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 18, 2006 7:23 pm |
|
|
Quote: | 1)HOW DO I ADD MESSAGE BEFORE THIS \f%x?? I ADDED A
MESSAGE THE LCD SHOWED IT REPEATEDLY....PLS HELP |
Just add the message after the \f. See example shown in bold below:
Quote: |
{
value = input_b();
printf(lcd_putc, "\fValue is: %x", value); --
delay_ms(1000);
} |
Quote: | 2)How do i convert first 7 bits of input to Integer ?
|
Do a bitwise AND with 0x7F. Example:
Code: |
int8 result;
result = value & 0x7F;
|
Quote: | and use eighth bit as an error bit? |
Mask down the value by ANDing it with 0x80 to isolate the top bit.
Then use an "if()" statement to do something if the top bit is set.
Example:
Code: | if(value & 0x80)
{
// do something here if top bit is equal to 1.
} |
|
|
|
RAHUL Guest
|
The code I tried |
Posted: Tue Mar 21, 2006 1:11 pm |
|
|
\This is what I plan on doing:
0)The LCD should be clear screen then show"Welcome" till it reveives input at D0.(i do not want to display the previous message in PIC memory)
1)I want to START the LCD when the PIC receives a high input(FROM SWITCH) at pin D0.
2)The LCD should display"Measuring...."till it receives 8 bit parallel input.(The problem is the time in which it receives 8 bit input can vary everytime.)
This is the code I have:
While(1)
{lcd_init();
printf(lcd_putc,�WELCOME!!�);
delay_ms(1000);
IF (input(pin_D0))
{
printf(lcd_putc,"Measuring�.�);
delay_ms(1000);
value = input_b();
if(value!=00000000)//tried 0 too
{
if(value & 0x80)
{printf(lcd_putc,"ERROR!!");
delay_ms(1000);
}
else
{result = value & 0x7F;
printf(lcd_putc,"\fGrain Depth:\n");
printf(lcd_putc,"%u",result);
delay_ms(1000);
}
}
}
}
The code doesnot work.Kindly guide me.
Waiting for a reply. |
|
|
|
|
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
|