Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to pass value to lcd?

Status
Not open for further replies.

lizxay

Newbie level 2
Joined
Oct 3, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
Hi everyone, I have written my coding to count the revolution per minute of a motor, does anyone know how to pass the counted value to lcd? how to write it ? my coding is below, i really need u guys help, thanks a lot, if u guys feel it's too long, u can straight jump to the void value() part, it's that part i need help =)


#include<pic.h>
__CONFIG(0x3f18);
//__CONFIG_DEBUG_0FF&_CP_ALI&_WRT_HALF&_CPD_ON&_LVP_0FF&_BODKN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC

#define rs RA0
#define rw RA2
#define e RA1

const char label[]={' ','S','P','E','E','D',':'};

const char unit[]={'R','P','M',' '};

void start();
void delayloop();

void init(); //I/O port initialize function declare
void lcd_init(); //LCD init
void write_label();
void write_unit();
void write(char x); //display one byte
void lcd_enable(); //LCD display setting
void delay(); //delay

void main(){
while(1){

start();
RA2=1;
init();
lcd_init();
write_label();
PORTB=0xC0; //set the 2nd line display address
write_unit();
lcd_enable(); //LCD display setting
}
}
void start(){
int timerstart,timerstop,count,duration,rpm;
STATUS=STATUS&0b00100000;
TRISA=0x04;
TRISB=0x00;

T1CON=0b00101101;

STATUS=STATUS&0b00000000;
PORTA=0x00;
PORTB=0x00;

start:
if(PORTA&0b00000100){
goto input;
}
else{
goto start;
}

input:
timerstart=TMR1H;
delayloop();

start2:
if(PORTA&0b00000100){
goto input2;
}
else{
goto start2;
}

input2:
timerstop=TMR1H;
delayloop();

if(timerstop > timerstart){
duration=timerstop-timerstart;
}

else{
duration= timerstop + 60 - timerstart;
}

rpm=60/duration;

}


void delayloop()
{
int i;
for(i=0;i<5000;i++);
}

//initialize I/O

void init()
{
CMCON=0x07;
TRISA=0x00;
TRISB=0x00;
}
//-------------------------------------------------------
//LCD init

void lcd_init()
{
PORTB=0x1; //clear screen
lcd_enable();
PORTB=0x38; //8 bits 2 lines 5*7 mode
lcd_enable();
PORTB=0x0e; //display on, cursor on, blink on
lcd_enable();
PORTB=0x06; //character not move, cursor rotate right
lcd_enable();
PORTB=0x80; //www.ahchye.com
lcd_enable();
}

//--------------------------------------------------------------

void write_label()
{
int i;
for(i=0;i<0x07;i++)
{
write(label); //search table
}
}

void write_value()
{

"THIS PART IS TO WRITE AND PASS THE RPM VALUE"
}

void write_unit()
{
int i;
for(i=12;i<0x0F;i++)
{
write(unit);
}
}



//--------------------------------------------------------------
//write a byte to led
void write (char x)
{
PORTB=x; //data send to PORTB
rs=1; //is data not command
rw=0; //is write not read
e=0; //pull low enable signal
delay(); //for a while
e=1; //pull high to build the rising edge
}

//lcd display setting
void lcd_enable()
{
rs=0; //is command not data
rw=0; //is write not read
e=0; //pull low enagle signal
delay(); //for while
e=1; //pull high to build the rising edge
}

//-----------------------------------------------
//delay
void delay()
{
int i;
for(i=0;i<5000;i++);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top