t.man
New Member
i'm trying to send characters to the dispaly but failed, i'm not even sure that the display do initialize.
i'm using KS0066U dased lcd(i.e PC1602F from POWERTIP company). it is a 16 pin display.
my hardware configurations:
LCD------------MCU(ATmega8)
Vss-------------------------->POWER SUPPLY(GND)
Vdd-------------------------->POWER SUPPLY(+5v)
Vo(Contrast Adjust)---------->(120 ohm to GND)
DB7-------------PD7
DB6-------------PD6
DB5-------------PD5
DB4-------------PD4
(DB3-DB0) tied to ground
(PIN 15 & 16 ) not connected
software
main.h
main.c
i need help!
i'm using KS0066U dased lcd(i.e PC1602F from POWERTIP company). it is a 16 pin display.
my hardware configurations:
LCD------------MCU(ATmega8)
Vss-------------------------->POWER SUPPLY(GND)
Vdd-------------------------->POWER SUPPLY(+5v)
Vo(Contrast Adjust)---------->(120 ohm to GND)
DB7-------------PD7
DB6-------------PD6
DB5-------------PD5
DB4-------------PD4
(DB3-DB0) tied to ground
(PIN 15 & 16 ) not connected
software
main.h
Code:
#ifndef MAIN_H
#define MAIN_H
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#define LCD_DATA_PORT PORTD
#define LCD_DATA_DDR DDRD
//define lcd control port
#define LCD_CTRL_PORT PORTB
#define LCD_CTRL_DDR DDRB
#define LCD_rs 0
#define LCD_rw 1
#define LCD_en 2
// LCD instructions
#define LCD_start() LCD_command(0x20) /* Send 0x2(0) */
#define LCD_function_set() LCD_command(0x28) /* LCD function set */
#define LCD_display_off() LCD_command(0x08) /* LCD display off*/
#define LCD_display_on() LCD_command(0x0F) /* LCD display on*/
#define LCD_display_clear() LCD_command(0x01)/* Clear display LCD */
#define LCD_mode_set() LCD_command(0x06) /* LCD mode set */
//functions declarations
void LCD_enable();
void LCD_command(unsigned char command);
void LCD_putc(unsigned char ascii);
void LCD_puts(unsigned char *lcd_string);
void LCD_init();
#endif
main.c
Code:
#include "main.h"
unsigned char text[] = "AVR Project";
int main()
{
LCD_init();
LCD_puts(text);
}
void LCD_enable()
{
LCD_CTRL_PORT |= (1<<LCD_en);
_delay_ms(1);
LCD_CTRL_PORT &= ~(1<<LCD_en);
}
void LCD_command(unsigned char command)
{
LCD_CTRL_PORT &= ~(1<<LCD_rs);
LCD_DATA_PORT = (command & 0xF0)|(LCD_DATA_PORT & 0x0F);
LCD_enable();
LCD_DATA_PORT = (command << 4 & 0xF0)|(LCD_DATA_PORT & 0x0F);
LCD_enable();
_delay_ms(1);
}
void LCD_putc(unsigned char ascii)
{
LCD_CTRL_PORT |= (1<<LCD_rs);
LCD_DATA_PORT = (ascii & 0xF0)|(LCD_DATA_PORT & 0x0F);
LCD_enable();
LCD_DATA_PORT = (ascii << 4 & 0xF0)|(LCD_DATA_PORT & 0x0F);
LCD_enable();
_delay_ms(1);
}
void LCD_puts(unsigned char *lcd_string)
{
while (*lcd_string)
{
LCD_putc(*lcd_string++);
}
}
void LCD_init()
{
//initialize LCD control lines
LCD_CTRL_PORT &= ~(1<<LCD_rs); // RS low
LCD_CTRL_PORT &= ~(1<<LCD_rw); // R/W low
LCD_CTRL_PORT &= ~(1<<LCD_en); // E low
// initialize LCD control lines to output
LCD_CTRL_DDR |= (1<<LCD_rs);
LCD_CTRL_DDR |= (1<<LCD_rw);
LCD_CTRL_DDR |= (1<<LCD_en);
// initialize LCD data port to input
LCD_DATA_DDR |= 0xF0;// Data on high four bits of port
_delay_ms(30);
LCD_start();
LCD_function_set();
_delay_us(40);
LCD_display_off();
_delay_us(40);
LCD_display_clear();
_delay_ms(2);
LCD_mode_set();
LCD_display_on();
}
i need help!
Last edited: