|
发表于 2009-11-15 14:15:42
|
显示全部楼层
Altera DE2 例程
test.c
-----------------------------------------------------------------------------------------
#include "LCD.h" // LCD1602
//----------------------------------------------------------
int main(void)
{
// -> ---------------- <- // 16bits
char Line1[16] = "LCD1602 Test";
char Line2[16] = "by yf.c";
LCD_Test(Line1, Line2);
return 0;
}
//----------------------------------------------------------
-----------------------------------------------------------------------------------------
LCD.h
-----------------------------------------------------------------------------------------
#ifndef __LCD_H__
#define __LCD_H__
// LCD Module 16*2
#define lcd_write_cmd(data) IOWR(LCD1602_BASE, 0, data)
#define lcd_read_cmd() IORD(LCD1602_BASE, 1)
#define lcd_write_data(data) IOWR(LCD1602_BASE, 2, data)
#define lcd_read_data() IORD(LCD1602_BASE, 3)
//----------------------------------------------------------
void LCD_Init();
void LCD_Show_Text(char* Text);
void LCD_Line2();
void LCD_Test(char* Text1, char* Text2);
//----------------------------------------------------------
#endif
-----------------------------------------------------------------------------------------
LCD.c
-----------------------------------------------------------------------------------------
#include <unistd.h>
#include <string.h>
#include <io.h>
#include "system.h"
#include "LCD.h"
//----------------------------------------------------------
void LCD_Init()
{
lcd_write_cmd(0x38); usleep(5000); // Display Mode
lcd_write_cmd(0x0C); usleep(5000); // Cursor Glint Mode
lcd_write_cmd(0x01); usleep(5000); // Clear Display
lcd_write_cmd(0x06); usleep(5000); // Cursor Move Forward Mode
lcd_write_cmd(0x80); usleep(5000); // Point to the Initial Address
}
//----------------------------------------------------------
void LCD_Show_Text(char* Text)
{
int i;
for(i=0;i<strlen(Text);i++)
{
lcd_write_data(Text); usleep(5000);
}
}
//----------------------------------------------------------
void LCD_Line2()
{
lcd_write_cmd(0xC0); usleep(5000);
}
//----------------------------------------------------------
void LCD_Test(char* Text1, char* Text2)
{
LCD_Init(); // Initial LCD
LCD_Show_Text(Text1); // Show Text of Line1 to LCD
LCD_Line2(); // Change Line2
LCD_Show_Text(Text2); // Show Text of Line2 to LCD
}
//---------------------------------------------------------- |
|