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.

i have a problem with lcd

Status
Not open for further replies.

vida

Newbie level 3
Joined
Dec 24, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,317
here is all my information:

#include <mega16.h>

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>

// Declare your global variables here


#include <stdio.h>
#include <math.h>
#include <stdlib.h>



// Declare your global variables here
int A;

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0xff;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xff;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0xff;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0xff;


// LCD module initialization
lcd_init(16);
lcd_clear();
lcd_gotoxy(0,0);

while (1)
{
A=PINC;
if(A<10){switch(A){
case 0:pORTD=0b10000001;lcd_putsf("0");lcd_gotoxy(0,0);break;
case 1:pORTD=0b11110011;lcd_putsf("1");lcd_gotoxy(0,0);break;
case 2:pORTD=0b01001001;lcd_putsf("2");lcd_gotoxy(0,0);break;
case 3:pORTD=0b01100001;lcd_putsf("3");lcd_gotoxy(0,0);break;
case 4:pORTD=0b00110011;lcd_putsf("4");lcd_gotoxy(0,0);break;
case 5:pORTD=0b00100101;lcd_putsf("5");lcd_gotoxy(0,0);break;
case 6:pORTD=0b00000101;lcd_putsf("6");lcd_gotoxy(0,0);break;
case 7:pORTD=0b11110001;lcd_putsf("7");lcd_gotoxy(0,0);break;
case 8:pORTD=0b00000001;lcd_putsf("8");lcd_gotoxy(0,0);break;
case 9:pORTD=0b00100001;lcd_putsf("9");lcd_gotoxy(0,0);break;
}
}





}

}
with this program,lcd &7segment show numbers between 0&3.it cann't show numbers between 4&9
my lcd is 2x16
and it is a character lcd
 

You are calling the lcd/led function many thousand times per second, use a delay_ms(200) inside the while
to limit the refresh to 4-5 times/sec or lower.
What is you input on portC, do you use switches to ground the pins.
You have internal pull ups to all pins so the initial value is 255 (all 1s),
you have to ground all pins externally and then disconnect only the pins you want enabled.
For example for 3 you want 00000011 so you must disconnect the ground from pin 0 and 1 of portC.
The second solution is to use A=~PINC
In this case the default value will be the inverse of 11111111 which is 00000000 so you
only have to ground the pins you want enabled.
If for example you ground pins 0 and 1 of portC (others pins floating) then pinC will be 11111100 and ~pinC will be 00000011 which is value 3.

Alex
 

In your program you had used LCD in PORTA and using the same for input.
Either change the lcd port or input port
 

In your program you had used LCD in PORTA and using the same for input.
Either change the lcd port or input port

The code is written with codevision, the code in the first lines
Code:
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
defines the lcd port to portA and lcd_init() called later initializes the port direction (I/O) correctly as output.
portA in not used anywhere else as input.

Alex
 

The code is written with codevision, the code in the first lines
Code:
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
defines the lcd port to portA and lcd_init() called later initializes the port direction (I/O) correctly as output.
portA in not used anywhere else as input.

Alex

Sorry my mistake
May be JTAG Enabled. If so disable JTAG
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top