PA3040
Advanced Member level 3
- Joined
- Aug 1, 2011
- Messages
- 883
- Helped
- 43
- Reputation
- 88
- Reaction score
- 43
- Trophy points
- 1,308
- Activity points
- 6,936
Dear All,
My Xmega128A1 with HD44780 LCD program does not working
It should be much appreciated if any one can advice me
Thanks in advance
My Xmega128A1 with HD44780 LCD program does not working
It should be much appreciated if any one can advice me
Code:
[COLOR=#008000][FONT=Courier New]/* [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] * My_first.c [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] * [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] * Created: 8/11/2013 9:49:37 PM [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] * Author: dayan [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] */ [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#include <avr/io.h> [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#include <util/delay.h> [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#define LCD_RS PIN4_bm /* RS on pin PC4 */ [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#define LCD_RW PIN5_bm /* R/W on pin PC5 */ [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#define LCD_E PIN7_bm /* E on pin PC7 */ [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#define my_led1 PIN0_bm //000000001 0x01 [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#define COMM_PORT PORTC [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#define DATA_PORT PORTB [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]#define BLINK_DELAY_MS 500 [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]uint8_t lcd_port [5] = {"test"}; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]uint8_t seg =0; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]uint8_t led = 0; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] void main(void){ [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] PORTF.OUTSET = 0XFF; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] PORTF.DIRSET = 0b00001111 ; // Set pin 0 to be output. [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] PORTJ.DIRSET = 0b11111111 ; // Set pin 0 to be output. [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] PORTH.OUTCLR = 0Xff; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] PORTH.DIRSET = 0b11111111 ; // Set pin 0 to be output for segments [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] PORTC.DIRSET = 0b11111111 ; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] while(1){ [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] test_led(); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_init(); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_display(); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] } [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]} [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]void lcd_init() { [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] // Initialize the AVR ports and any other hardware bits [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] DATA_PORT.OUT = 0x00; // initial data lines all low [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUT = 0X00; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] DATA_PORT.DIRSET = 0xff; // set the 8-bit data port to all outputs [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.DIRSET = 0Xff; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] // startup delay - make it long to allow time for power to settle [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] // (you want wish to remove this line) [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(50); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] // LCD display initialization by instruction magic sequence [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_commnd(0x38); // function set [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(50); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_commnd(0x38); // function set [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(50); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_commnd(0x01); // display on/off control [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(50); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_commnd(0x02); //move cursor to top/left character position [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(50); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_commnd(0x0f); // display clear [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(50); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_commnd(0x06); // entry mode set [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(50); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_commnd(0x14); // Cursor shift [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]} [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]//This function sets the RS line to write data [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]void lcd_data(unsigned char value) { [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] DATA_PORT.OUT = value; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUTSET = LCD_RS; // set RS line high [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUTCLR = LCD_RW; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUTSET = LCD_E; // set E line high [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(1); //_delay_ms(1); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUTCLR = LCD_E; // set E line low to latch data into LCD [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] } [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]// This function writes a byte to the LCD [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]void lcd_commnd(unsigned char value) { [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] DATA_PORT.OUT = value ; // Place data on Data Port [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUTCLR = LCD_RS; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUTCLR = LCD_RW; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUTSET = LCD_E; // set E line high [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms(1); //_delay_ms(1); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] COMM_PORT.OUTCLR = LCD_E; // set E line low to latch data into LCD [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]} [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]void lcd_display(){ [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] unsigned int x; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] for (x=0;x<5;x++) [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] { [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] lcd_data(lcd_port[x]); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] } [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]} [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]void test_led(){ [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] PORTF.OUTCLR = my_led1; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms( BLINK_DELAY_MS ); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] PORTF.OUTSET = my_led1; [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New] _delay_ms( BLINK_DELAY_MS ); [/FONT][/COLOR]
[COLOR=#008000][FONT=Courier New]} [/FONT][/COLOR]
Thanks in advance