/* * LCD.c * * Created: 2019-05-10 14:09:37 * Author: an2657re-s */ #include int chip = 1; void LCD_init() { DDRD = 0xff; DDRB = 0xff; PORTB = 0b00000000; PORTD = 0x00; } void LCD_on() { PORTD = 0b00111111; PORTB &= ~(0b00011011); PORTB |= (0b00000101); LCD_execute(); PORTB &= ~(0b00011011); PORTB |= (0b00000110); LCD_execute(); } void LCD_execute(){ executeDelay(); PORTB |= 0b00100000; executeDelay(); PORTB &= 0b11011111; } void LCD_off() { PORTD = 0b00111110; PORTB &= ~(0b00011000); PORTB |= (0b00000101); LCD_execute(); PORTB |= (0b00000110); LCD_execute(); } void LCD_clear() { for(int i = 0; i < 8; i++){ for(int j = 0; j <128; j++){ LCD_write(i,j, 0x00); } } } void LCD_setX(uint8_t page) { //Between 0-7 PORTD = (0b10111000 + page); PORTB &= ~(0b00011000); //D/I R/W --> 0 LCD_execute(); } void LCD_setY(uint8_t add) { PORTD = (0b01000000 + add); PORTB &= ~(0b00011000); //D/I R/W --> 0 LCD_execute(); } void LCD_test(){ } void LCD_write(uint8_t x, uint8_t y, uint8_t byte) //x<8, y<128 { DDRD = 0b11111111; //Select chip if (y < 64) { chipOne(); executeDelay(); } else { chipTwo(); executeDelay(); y=y-64; } //write y address LCD_setY(y); //write x address LCD_setX(x); //write data PORTB |= (0b00010000); // D/I --> 1 PORTB &= ~(0b00001000); //R/W --> 0 PORTD = byte; LCD_execute(); } void LCD_drawBorder(){ for(int i = 0; i < 127; i++){ //Lägsta LCD_write(0,i,0x01); } for(int i = 0; i < 127; i++){ //Högsta LCD_write(7,i,0x80); } for(int i = 0; i < 8; i++){ // höger LCD_write(i,0,0xFF); } for(int i = 0; i < 8; i++){ //vänster LCD_write(i,127,0xFF); } } void chipOne(){ PORTB |= (1<<0); PORTB &= ~(1<<1); } void chipTwo(){ PORTB |= (1<<1); PORTB &= ~(1<<0); }