I have this code that I want to fiddle with, analyze an hopefully learn m ore about it. It is suppose to make Atmega32 operate an LCD display without the use of proper Libraries.
I'm new to this - I'm trying to figure out through which pins should be the controller connected with (i mean, 4 data pins, en and rs). And I need help with this.
Here comes the code:
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/delay.h>
void wait_ms(int del) {
for (int i=0; i<del; i++) {
_delay_ms(1);
}
}
void LCD_command(int c) {
int d;
d=c;
PORTB = c >> 4;
PORTD = 0x01;
wait_ms(1);
PORTD = 0x00;
wait_ms(1);
PORTB = d;
PORTD = 0x01;
wait_ms(1);
PORTD = 0x00;
wait_ms(1);
}
void LCD_char(char c) {
char d;
d=c;
PORTB = (c & 0xf0) >> 4;
PORTD = 0x03;
wait_ms(1);
PORTD = 0x02;
wait_ms(1);
PORTB = d & 0x0f;
PORTD = 0x03;
wait_ms(1);
PORTD = 0x02;
wait_ms(1);
}
void LCD_text(char *s) {
while (*s) {
LCD_char(*s);
s++;
}
}
void LCD_IR(void) {
PORTD = 0x01;
wait_ms(1);
PORTD = 0x00;
wait_ms(1);
}
void LCD_init(void) {
wait_ms(20);
LCD_command(0x03);
LCD_command(0x03);
LCD_command(0x03);
LCD_command(0x02);
LCD_command(0x28);
LCD_command(0x01);
LCD_command(0x06);
LCD_command(0x0f);
}
int main(void) {
DDRB = 0xFF;
DDRD = 0xFF;
LCD_init();
char s[10];
//LCD_char('t');
//char w = "zmienna";
LCD_text(s);
while (1);
}
Once I have this up and running I will most probably be able to figure out where to go with this. I just need this push.
Oh - I'm working with Kamami Board with the LCD already installed on it (just need to connect the pins). Hope you know what i'm talking about.