|
|
View previous topic :: View next topic |
Author |
Message |
qali246
Joined: 13 Apr 2007 Posts: 2 Location: Coventry,UK
|
Send data to LCD from PIC |
Posted: Mon Apr 30, 2007 1:39 pm |
|
|
I am a student having a final project based on the automotive CAN-Bus system.
For my project I planed to simulate the sensor with a potentiometer connected to a PIC18F4580. The value picked by the PIC are sent to my lcd drive by a PI16F874 via a MCP2510.
I wrote a sample code for the moment and I need some feedback concerning the errors or syntax.
/////////////////////////////////////////////////////////////////////////////////////
//code for the PIC18F//
#include <18f4580.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT,
#use delay (clock=20000000)
#include<can-18F4580.c>
#define GREEN PIN_A5
#define RED PIN_B1
#define YELLOW PIN_B4
#define WRITE_REGISTER_D_ID 0X400 //Destination of the frames (LCD connect with a MCP2510)
void main()
{
int reading,kmH;
setup_port_A(ALL_ANALOG); //port A analog
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0); //read value at the potentiometer
can_init(); //PIC initialisation
can_putd (0x100,0,0,1,TRUE,FALSE); //departure of the values
delay_ms (1000); //wait until MCP2510 wakes up
while (TRUE)
{
reading=read_adc();
//255 samples=>63=1.18V ; 180=3.52V; thx to the fomular:(reading*5V)/255
if (reading<63)
{
output_low(GREEN); //for low speed 0<kmH<50 dividing reading/1.28*
output_high(RED);
output_high(YELLOW);
}
else if (reading<167)
{
output_low(YELLOW); //for indicate average speed 50<kmh<130>180)
{
output_low(RED); //speed to high slow dowm!!! kmH>130*
delay_ms(500);
output_high(RED);
delay_ms(500);
output_high(YELLOW);
}
}
kmH=reading/1.28; //calculate the reading A/D in Kilometer per hour
can_putd(WRITE_REGISTER_D_ID, kmH, 3, 1, TRUE, FALSE); //send value read to node D
}
/////////////////////////////////////////////////////////////////////////////////////
//code for the PIC16F//
#include <16F874.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay (clock=20000000)
#include <flexlcd.c>
#include <can-mcp2515.c>
#DEFINE WRITE_REGISTER_V_ID 0x100 //NODEV
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main()
{
int32 rx_id
int rx_len, rx_stat, kmH,buffer
// The lcd_init() function should always be called once,
lcd_init();
can_init();
buffer[3]={0x10E,0x7F,kmH};
while(TRUE)
{
delay_ms(8) //delay of updated data
if (can_kbhit() )
{
if (can_getd (rx_id, &buffer[?], 3, 1,rx_len,rxstat)
{
if (rx_id==WRITE_REGISTER_V_ID) //if ID==the one of nodeV
lcd_gotoxy(1,1): //write the value on the first line
printf(lcd_putc,"Velocity=buffer[2]")
}
}
}
} |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
|
Posted: Mon Apr 30, 2007 3:01 pm |
|
|
1) please use the "Code" tags to properly format your code.
2) please don't make us guess what the problem may be.
-- what version compiler do you have?
-- does your code compile?
-- if not, what error is shown and at what line number?
-- does your code actually run? if not, what are the symptoms?
-- does your code display anything on the LCD?
-- what did you expect it to display?
-- what does it display?
3) please add some detail regarding your hardware configuration. no one here is capable of internet-assisted remote telepathy.
jds-pic |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
Re: Send data to LCD from PIC |
Posted: Mon Apr 30, 2007 3:06 pm |
|
|
ps:
qali246 wrote: | I am a student...
Code: |
int reading,kmH;
...
kmH=reading/1.28; //calculate the reading A/D in Kilometer per hour
|
|
what do you think the result of dividing an integer by a float and storing the result as an integer is going to be?
jds-pic |
|
|
|
|
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
|