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.

atmega16 lcd codevision

Status
Not open for further replies.

tsibos22

Newbie level 5
Joined
Sep 17, 2011
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
hi all,
Sorry for my bad english,
i have problem programming lcd. I am using a 16x2 HD44780 alpharithmetic lcd and atmega16 with codevision
My code is
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3a Evaluation
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 9/17/2011
Author  : Freeware, for evaluation and
non-commercial use only
Company : 
Comments: 


Chip type               : ATmega16L
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include <mega16.h>

// Alphanumeric LCD functions
#include <alcd.h>

// Declare your global variables here

void main(void)
{
MCUCSR=0x80;
MCUCSR=0x80;
// 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=0x00;

// 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=0x00;

// 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=0x00;
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=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// USART disabled
UCSRB=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 16
lcd_init(16);
              
// go on the second LCD line
lcd_gotoxy(0,1);

// display the message
lcd_putsf("Hello world");
while (1)
      {
      // Place your code here

      }
}
Any help?
Thanks a lot!!!!
 
Last edited:

What exactly is your problem? What is the lcd's behaviour when you run your code?
As far as I can see the lcd is on PORTC. Do you make PORTC pins outputs using the DDRC register?

Code:
DDRC=0x00;

This means that PORTC is used as an input port in your program. Please read ATmega16 datasheet at the I/O Port section for more details.

http://www.atmel.com/dyn/resources/prod_documents/doc2466.pdf
 

Thanks for the answer. I change the DDRC(DDRC=0xFF;) register but nothing. The problem is that on the lcd is getting black the firtst row (i think that the lcd is not installed) and it is not change the state of the lcd

---------- Post added at 14:44 ---------- Previous post was at 14:39 ----------

Is possimle my lcd is spoiled?
 

Have you made the proper connections?
For 4bit operation D0,D1,D2,D3 should be grounded
lcd.png

Also there is no need to set the port direction, the CVAVR LCD library does it internally (in the library) for the defined pins (PORTC in this case)

The R/W can either be hardwired for read only mode (as shown in the schematic above) or your can connect it to PORTC

Alex
 

PORTC in atmega 16 is also used for jtag.

Disable jtag, it will work
 
Yes that is the circuit.
I used to be use avr studio and this is my first program in codevision. So i want to be sure for the programming steps on codevision
1) i create a new project and i choose what ia use (chip,pwm,lcd in my case i choose the chip and lcd only)
2) i save the files(generate save exit button)
3) i write the code
4)in configure project button i choose to program the chip
5) in built the project button i choose program the chip
am i rong in something?

---------- Post added at 15:53 ---------- Previous post was at 15:50 ----------

When i connect the led wires the backround led is not work in lcd but all the first row is black. Is maybe my lcd spoiled?(sorry again for my bad english)

---------- Post added at 16:01 ---------- Previous post was at 15:53 ----------

PORTC in atmega 16 is also used for jtag.

Disable jtag, it will work
I use this programmer and the board is hand made(pcb) this programmer uses mosi miso sck rst vcc and gnd pins is not use portc. I try this but it is not worked( i program the chip i disable the programmer and i reset the chip it is not worked thaks for the reply
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top