c - How to connect pins on Atmega32 to 4 bit LCD so this code works -
i have code want fiddle with, analyze learn m ore it. suppose make atmega32 operate lcd display without use of proper libraries.
i'm new - i'm trying figure out through pins should controller connected (i mean, 4 data pins, en , rs). , need this.
here comes code:
#define f_cpu 16000000ul #include <avr/io.h> #include <avr/delay.h> void wait_ms(int del) { (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 have , running able figure out go this. need push.
oh - i'm working kamami board lcd installed on (just need connect pins). hope know i'm talking about.
you didn't give enough information in question you. there many kamani boards , several lcd screens. didn't see avr board lcd, though. code work on such board?
anyway, can see code looking @ it.
portb seems 4-bit data bus. portb = (c & 0xf0) >> 4;
sends high bits of c
on pins portb0:3. later, portb = c & 0x0f;
sends out low bits.
portd pins 0 , 1 seem clock , command bits. (maybe labelled en , rs, doubt it.) portd0 toggled between 0 , 1 @ correct times. portd1 0 command, , 1 data.
you should find datasheet lcd display using, , see if uses 4-bit data , clock , command pins. read number off device , search on internet.
Comments
Post a Comment