用iar for avr 实现12864液晶显示屏驱动移植源代码
时间: 2024-01-21 10:19:53 浏览: 218
key_lcd.rar_AVR IAR_avr keypad_avr 程序模块_iar keypad
以下是一个基于 IAR for AVR 的 12864 液晶显示屏驱动移植源代码,仅供参考:
```c
#include "lcd12864.h"
#include <iom128.h>
#define LCD_DATA_PORT PORTA
#define LCD_DATA_DDR DDRA
#define LCD_CTRL_PORT PORTC
#define LCD_CTRL_DDR DDRC
#define LCD_RS_PIN PC0
#define LCD_RW_PIN PC1
#define LCD_EN_PIN PC2
void LCD_Init()
{
LCD_CTRL_DDR |= (1 << LCD_RS_PIN) | (1 << LCD_RW_PIN) | (1 << LCD_EN_PIN);
LCD_DATA_DDR = 0xFF;
LCD_CTRL_PORT &= ~(1 << LCD_RS_PIN);
LCD_CTRL_PORT &= ~(1 << LCD_RW_PIN);
LCD_CTRL_PORT &= ~(1 << LCD_EN_PIN);
LCD_WriteCommand(0x30);
delay_us(4500);
LCD_WriteCommand(0x30);
delay_us(4500);
LCD_WriteCommand(0x30);
delay_us(150);
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x08);
LCD_WriteCommand(0x01);
LCD_WriteCommand(0x06);
LCD_WriteCommand(0x0C);
}
void LCD_WriteCommand(unsigned char cmd)
{
LCD_CTRL_PORT &= ~(1 << LCD_RS_PIN);
LCD_CTRL_PORT &= ~(1 << LCD_RW_PIN);
LCD_CTRL_PORT |= (1 << LCD_EN_PIN);
LCD_DATA_PORT = cmd;
delay_us(1);
LCD_CTRL_PORT &= ~(1 << LCD_EN_PIN);
delay_us(10);
}
void LCD_WriteData(unsigned char data)
{
LCD_CTRL_PORT |= (1 << LCD_RS_PIN);
LCD_CTRL_PORT &= ~(1 << LCD_RW_PIN);
LCD_CTRL_PORT |= (1 << LCD_EN_PIN);
LCD_DATA_PORT = data;
delay_us(1);
LCD_CTRL_PORT &= ~(1 << LCD_EN_PIN);
delay_us(10);
}
void LCD_Clear()
{
LCD_WriteCommand(0x01);
}
void LCD_SetCursor(unsigned char row, unsigned char col)
{
unsigned char address = (row == 0 ? 0x00 : 0x40) + col;
LCD_WriteCommand(0x80 | address);
}
void LCD_WriteString(char* str)
{
while(*str)
{
LCD_WriteData(*str++);
}
}
void delay_us(unsigned int n)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < 3; j++)
{
asm("nop");
}
}
}
```
在此基础上,你需要根据你的具体硬件连接情况进行适当的修改。
阅读全文