improved LCD code and changed pins

This commit is contained in:
Stefan Rupp 2014-03-01 23:52:49 +01:00
parent ccd35a9ad7
commit f036f73bb8
2 changed files with 24 additions and 19 deletions

View File

@ -1,5 +1,5 @@
PRG = rgbyteclock
OBJ = rgbyteclock.o timer.o lcd.o main.o rtc.o spi.o ringbuffer.o crc.o
OBJ = rgbyteclock.o timer.o lcd.o main.o rtc.o spi.o ringbuffer.o crc.o led1642gw.o
MCU_TARGET = atmega164a
OPTIMIZE = -Os
@ -25,15 +25,15 @@ $(PRG).elf: $(OBJ)
@echo
# dependency:
rgbyteclock.o: timer.o lcd.o rgbyteclock.h rtc.o
main.o: rgbyteclock.o
rgbyteclock.o: timer.o lcd.o rgbyteclock.h rtc.o spi.o led1642gw.o
main.o: rgbyteclock.o lcd.o spi.o led1642gw.o
timer.o: timer.h
lcd.o: lcd.h
lcd.o: lcd.h timer.o
rtc.o: rtc.h
spi.o: spi.h
spi.o: spi.h crc.o ringbuffer.o
ringbuffer.o: ringbuffer.h
crc.o: crc.h
led1642gw.o: led1642gw.h
clean:
rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak

29
lcd.c
View File

@ -16,7 +16,13 @@
#include "timer.h"
#include "lcd.h"
//#define WAIT_250_ns() _delay_us(1)
#define LCD_DATA_PIN (PINA)
#define LCD_DATA_PORT (PORTA)
#define LCD_DATA_DIR (DDRA)
#define LCD_DATA_MASK (0x0f)
#if (F_CPU <= 4000000UL)
#define WAIT_250_ns() _NOP()
#elif (F_CPU <= 8000000UL)
@ -32,15 +38,15 @@
#define WAIT_250_ns() _delay_us(1)
#endif
#define LCD_DATA_MODE() (PORTD |= (1<<PD6))
#define LCD_CMD_MODE() (PORTD &= ~(1<<PD4))
#define LCD_DATA_MODE() (PORTA |= (1<<PA4))
#define LCD_CMD_MODE() (PORTA &= ~(1<<PA4))
#define LCD_SET_ENABLE() (PORTD |= (1<<PD5))
#define LCD_RESET_ENABLE() (PORTD &= ~(1<<PD5))
#define LCD_SET_ENABLE() (PORTA |= (1<<PA6))
#define LCD_RESET_ENABLE() (PORTA &= ~(1<<PA6))
// !!!!!!!
#define LCD_SET_READ() DDRA &= ~(0x0f);PORTA &= ~(0x0f);PORTD |= (1<<PD7)
#define LCD_SET_WRITE() PORTD &= ~(1<<PD7);DDRA |= 0x0f
#define LCD_SET_READ() LCD_DATA_DIR &= ~(LCD_DATA_MASK);LCD_DATA_PORT &= ~(LCD_DATA_MASK);PORTA |= (1<<PA5)
#define LCD_SET_WRITE() PORTA &= ~(1<<PA5);LCD_DATA_DIR |= LCD_DATA_MASK
// !!!!!!!
@ -58,7 +64,7 @@ static inline uint8_t lcd_read_byte(uint8_t RS)
LCD_SET_ENABLE();
WAIT_250_ns();
byte = (PINA<<4);
byte = (LCD_DATA_PIN<<4);
LCD_RESET_ENABLE();
WAIT_250_ns();
@ -66,7 +72,7 @@ static inline uint8_t lcd_read_byte(uint8_t RS)
LCD_SET_ENABLE();
WAIT_250_ns();
byte |= PINA & 0x0f;
byte |= LCD_DATA_PIN & 0x0f;
LCD_RESET_ENABLE();
return byte;
@ -87,7 +93,7 @@ static inline void lcd_wait_while_busy(void)
static inline void send_nibble(uint8_t nibble)
{
LCD_SET_WRITE();
PORTA = (PORTA & 0xf0) | (0x0f & nibble);
LCD_DATA_PORT = (LCD_DATA_PORT & 0xf0) | (0x0f & nibble);
LCD_SET_ENABLE();
WAIT_250_ns();
LCD_RESET_ENABLE();
@ -158,8 +164,7 @@ void lcd_init(void)
timer_wait(50);
// set CONTROL Pins as outputs:
DDRC = 0x3f;
DDRB |= (1<<PB0);
DDRA |= (0x70);
LCD_CMD_MODE();
LCD_SET_WRITE();