/*
KS0108 128*64 LCD C语言驱动
LCD引脚定义
1---GND
2---VCC
3---VLCD
4---D/I
5---R/W
6---E
7到14 D0-D7
15--CS1
16--CS2
17--RESET
18--VEE
19--SW
20--NC
*/
#include <iom16.h>
//#include <macros.h>
#include "delay.h"
unsigned char CurOffset,CurRow,CurPage,CurCol;
#define uchar unsigned char
/* 常量定义 */
#define LCD_STATUS_BUSY 0x80
#define START_LINE0 0xc0
#define DISPLAY_ON 0x3f
#define DISPLAY_OFF 0x3e
#define PARA1 0x40
#define BIT(x) (1<<x)
//PORTA---数据口 PORTB----控制口
volatile unsigned char *LCD_DIR_PORT = &DDRA;
volatile unsigned char *LCD_IP_PORT = &PINA;
volatile unsigned char *LCD_OP_PORT = &PORTA;
volatile unsigned char *LCD_EN_PORT = &PORTB;
volatile unsigned char *LCD_CS2_PORT = &PORTB;
volatile unsigned char *LCD_CS1_PORT = &PORTB;
volatile unsigned char *LCD_RW_PORT = &PORTB;
volatile unsigned char *LCD_DI_PORT = &PORTB;
char LCD_EN_BIT = BIT(4);
char LCD_CS2_BIT = BIT(3);
char LCD_CS1_BIT = BIT(2);
char LCD_RW_BIT = BIT(1);
char LCD_DI_BIT = BIT(0);
#define SET_LCD_E *LCD_EN_PORT |= LCD_EN_BIT //LCD使能
#define CLEAR_LCD_E *LCD_EN_PORT &= ~LCD_EN_BIT //LCD禁止
#define SET_LCD_DATA *LCD_DI_PORT |= LCD_DI_BIT //选择指令端口
#define SET_LCD_CMD *LCD_DI_PORT &= ~LCD_DI_BIT //选择数据端口
#define SET_LCD_READ *LCD_RW_PORT |= LCD_RW_BIT //读模式
#define SET_LCD_WRITE *LCD_RW_PORT &= ~LCD_RW_BIT //写模式
#define SET_LCD_CS2 *LCD_CS2_PORT |= LCD_CS2_BIT //左屏选择禁止
#define CLEAR_LCD_CS2 *LCD_CS2_PORT &= ~LCD_CS2_BIT //左屏选择使能
#define SET_LCD_CS1 *LCD_CS1_PORT |= LCD_CS1_BIT //左屏选择禁止
#define CLEAR_LCD_CS1 *LCD_CS1_PORT &= ~LCD_CS1_BIT //左屏选择使能
#define LEFT 0
#define RIGHT 1
#define CMD 0
#define DATA 1
void LCD_BUSY(unsigned char lr) //判断忙标志
{
unsigned char status;
asm("cli");
if(lr==LEFT)
{
CLEAR_LCD_CS2; //cs2=0
SET_LCD_CS1; //cs1=1
}
else
{
SET_LCD_CS2; //cs2=1
CLEAR_LCD_CS1; //cs1=0
}
SET_LCD_CMD;
*LCD_DIR_PORT = 0x00;
*LCD_OP_PORT = 0xff;
SET_LCD_READ;
SET_LCD_E;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
while((*LCD_IP_PORT) & LCD_STATUS_BUSY)
{
CLEAR_LCD_E;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
SET_LCD_E;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
CLEAR_LCD_E;
SET_LCD_WRITE;
*LCD_OP_PORT = 0xff;
asm("sei");//)asm("sei");
}
void write_LCD(unsigned char lr,unsigned char cd,unsigned char data) /*写入指令或数据*/
{
asm("cli");//)asm("cli");
LCD_BUSY(lr);
if(cd==CMD)
{
SET_LCD_CMD;
}
else
{
SET_LCD_DATA;
}
SET_LCD_WRITE;
SET_LCD_E;
*LCD_DIR_PORT = 0xff;
*LCD_OP_PORT = data;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
CLEAR_LCD_E;
*LCD_OP_PORT = 0xff;
asm("sei");
}
unsigned char read_LCD(unsigned char lr) /* 读显示数据 */
{
unsigned char data;
asm("cli");
LCD_BUSY(lr);
SET_LCD_DATA;
*LCD_DIR_PORT = 0x00;
*LCD_OP_PORT = 0xff;
SET_LCD_READ;
SET_LCD_E;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
data=*LCD_IP_PORT;
CLEAR_LCD_E;
SET_LCD_WRITE;
LCD_BUSY(lr);
SET_LCD_DATA;
*LCD_DIR_PORT = 0x00;
*LCD_OP_PORT = 0xff;
SET_LCD_READ;
SET_LCD_E;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
data=*LCD_IP_PORT;
CLEAR_LCD_E;
SET_LCD_WRITE;
asm("sei");
return data;
}
void set_start_line_L(unsigned char line) /*设置显示起始行*/ //0-63
{
write_LCD(LEFT,CMD,0xc0|line);
}
void set_start_line_R(unsigned char line) /*设置显示起始行*/ //0-63
{
write_LCD(RIGHT,CMD,0xc0|line);
}
void set_page_L(unsigned char page) /*设置X地址 设置页*/ //0-7
{
write_LCD(LEFT,CMD,0xb8|page);
}
void set_page_R(unsigned char page) /*设置X地址 设置页*/ //0-7
{
write_LCD(RIGHT,CMD,0xb8|page);
}
void set_col_addr_L(unsigned char col) /*设置Y地址*/ //0-63
{
write_LCD(LEFT,CMD,0x40|col);
}
void set_col_addr_R(unsigned char col) /*设置Y地址*/ //0-63
{
write_LCD(RIGHT,CMD,0x40|col);
}
void init_lcd(void) /*初始化函数*/
{
set_start_line_L(0); /*显示起始行为0*/
set_start_line_R(0); /*显示起始行为0*/
write_LCD(LEFT,CMD,DISPLAY_ON); /* 开显示 */
write_LCD(RIGHT,CMD,DISPLAY_ON); /* 开显示 */
}
void clr_lcd(void) /*清屏函数*/
{
unsigned char pages,i;
for(pages=0;pages<8;pages++)
{
set_page_L(pages); /* X 页地址 */
set_page_R(pages); /* X 页地址 */
for(i=0;i<64;i++)
{
set_col_addr_L(i);//Y
set_col_addr_R(i);//Y
write_LCD(LEFT,DATA,0x0);
write_LCD(RIGHT,DATA,0x0);
}
}
}
//ASCII 字模宽度及高度
#define ASC_CHR_WIDTH 8
#define ASC_CHR_HEIGHT 12
typedef struct typFNT_ASC16 /* 汉字字模显示数据结构 */
{
char Index[1];
char Msk[16];
};
__flash struct typFNT_ASC16 ASC_16[] =
{ /* 显示为8*16 Curier 10 常规*/
"1",0x00,0x00,0x08,0x08,0xFC,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x07,0x04,0x04,0x00,
"2",0x00,0x00,0x08,0x04,0x84,0x44,0x38,0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x00,
"3",0x00,0x00,0x08,0x04,0x44,0x44,0xB8,0x00,0x00,0x00,0x02,0x04,0x04,0x04,0x03,0x00,
"4",0x00,0x00,0x80,0x60,0x18,0xFC,0x00,0x00,0x00,0x00,0x01,0x01,0x05,0x07,0x05,0x00,
"5",0x00,0x00,0x7C,0x44,0x44,0x44,0x84,0x00,0x00,0x00,0x02,0x04,0x04,0x04,0x03,0x00,
"6",0x00,0x00,0xF0,0x48,0x44,0x44,0x80,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x03,0x00,
"7",0x00,0x00,0x0C,0x04,0x84,0x64,0x1C,0x00,0x00,0x00,0x00,0x06,0x01,0x00,0x00,0x00,
"8",0x00,0x00,0xB8,0x44,0x44,0x44,0xB8,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x03,0x00,
"9",0x00,0x00,0x38,0x44,0x44,0x44,0xF8,0x00,0x00,0x00,0x00,0x04,0x04,0x02,0x01,0x00,
"0",0x00,0x00,0xF8,0x04,0x04,0x04,0xF8,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x03,0x00,
".",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
",",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x04,0x00,0x00,0x00,
":",0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
";",0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x04,0x00,0x00,0x00,
"-",0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
"_",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
"A",0x00,0x00,0x80,0x64,0x1C,0x60,0x80,0x00,0x00,0x04,0x07,0x05,0x01,0x05,0x07,0x04,
"B",0x00,0x04,0xFC,0x44,0x44,0x44,0x44,0xB8,0x00,0x04,0x07,0x04,0x04,0x04,0x04,0x03,
"C",0x00,0xF0,0x08,0x04,0x04,0x04,0x04,0x08,0x00,0x01,0x02,0x04,0x04,0x04,0x04,0x02,
"D",0x00,0x04,0xFC,0x04,0x04,0x04,0x08,0xF0,0x00,0x04,0x07,0x04,0x04,0x04,0x02,0x01,
"E",0x00,0x04,0xFC,0x44,0x44,0xE4,0x04,0x0C,0x00,0x04,0x07,0x04,0x04,0x04,0x04,0x06,
"F",0x00,0x04,0xFC,0x44,0x44,0xE4,0x04,0x0C,0x00,0x04,0x07,0x04,0x04,0x00,0x00,0x00,
" ",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
"=",0x00,0x00,0xA0,0xA0,0xA0,0xA0,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
"(",0x00,0x00,0x00,0xE0,0x18,0x04,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x10,0x00,0x00,
")",0x00,0x00,0x00,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x00,0x10,0x0C,0x03,0x00,0x00,
"V",0x00,0x04,0x3C,0xC4,0x00,0xC4,0x3C,0x04,0x00,0x00,0x00,0x01,0x06,0x01,0x00,0x00,
"m",0x00,0x20,0xE0,0x20,0xC0,0x20,0xC0,0x00,0x00,0x04,0x07,0x00,0x07,0x00,0x07,0x04,
"H",0x00,0x04,0xFC,0x44,0x40,0x44,0xFC,0x04,0x00,0x04,0x07,0x04,0x00,0x04,0x07,0x04,
"*",0x90,0x90,0
没有合适的资源?快使用搜索试试~ 我知道了~
protues 与avr 实例
共361个文件
r90:59个
h:56个
c:53个
5星 · 超过95%的资源 需积分: 3 32 下载量 118 浏览量
2008-11-22
11:38:09
上传
评论 1
收藏 901KB RAR 举报
温馨提示
实例 经典的几个Proteus与avr仿真实例
资源推荐
资源详情
资源评论
收起资源包目录
protues 与avr 实例 (361个子文件)
m16_ad.a90 22KB
test1.a90 4KB
t6963_d90.aps 5KB
t6963_TEST_d90.aps 4KB
m16_ad_d90.aps 4KB
test1_d90.aps 3KB
m16_ad_a90.aps 3KB
test1_a90.aps 2KB
ks0108.c 21KB
t6963.c 12KB
LCD.c 7KB
LCD.c 7KB
LCD.c 7KB
LCD.c 7KB
LCD.c 7KB
key.c 7KB
LCD.c 6KB
ds1302.c 5KB
ds1302.c 5KB
hd44780.c 4KB
hd44780.c 4KB
main.c 4KB
main.c 3KB
main.c 2KB
main.c 2KB
main.c 2KB
mian.c 2KB
main.c 2KB
main.c 1KB
main.c 1KB
AD.C 1KB
main.c 1KB
main.c 1KB
usart.c 1010B
init.c 914B
horse.c 744B
usart.c 725B
usart.c 594B
delay.c 575B
delay.c 575B
delay.c 575B
delay.c 575B
delay.c 575B
delay.c 575B
delay.c 575B
delay.c 575B
delay.c 575B
delay.c 575B
delay.c 575B
usart.c 547B
usart.c 547B
usart.c 501B
main.c 455B
isr.c 354B
ISR.C 311B
number.c 311B
number.c 217B
number.c 217B
init.c 201B
init.c 201B
init.c 199B
ks0108.d90 30KB
ad.d90 28KB
240x64_t6963.d90 27KB
4bit_lcd.d90 24KB
4bit_ds1302.d90 23KB
pwm.d90 22KB
ds1302.d90 22KB
usart.d90 20KB
key_lcd.d90 18KB
time.d90 16KB
Numberdisplay.d90 15KB
conuter.d90 15KB
horselight.d90 10KB
ds1302.dbg 21KB
ds1302.dbg 21KB
Backup Of pwm.DBK 111KB
Last Loaded pwm.DBK 107KB
Backup Of time.DBK 100KB
Last Loaded time.DBK 100KB
Backup Of key_lcd.DBK 88KB
Last Loaded key_lcd.DBK 87KB
Backup Of usart.DBK 86KB
Last Loaded usart.DBK 86KB
Backup Of ad_da.DBK 86KB
Last Loaded ad_da.DBK 86KB
Backup Of 4bit_lcd.DBK 83KB
Last Loaded 4bit_lcd.DBK 82KB
Last Loaded Numberdisplay.DBK 81KB
Backup Of Numberdisplay.DBK 80KB
Last Loaded Numberdisplay.DBK 79KB
Backup Of Numberdisplay.DBK 79KB
Backup Of clock_lcd_8bit.DBK 66KB
Last Loaded clock_lcd_8bit.DBK 66KB
Backup Of horselight.DBK 64KB
Last Loaded ks0108.DBK 60KB
Last Loaded 1302.DBK 59KB
Backup Of 1302.DBK 59KB
Last Loaded m16_6963.DBK 18KB
Backup Of m16_6963.DBK 18KB
共 361 条
- 1
- 2
- 3
- 4
资源评论
- treasuredog2013-05-10很好,IAR环境下源码,内容完整。仿真文件还有中文注释。 正在学习中,十分感谢
- suyue20082012-01-13很好,IAR环境下源码,内容完整。仿真文件还有中文注释。谢谢分享!
- linhuikana2012-08-11还是不错的,注释的也蛮详细。适合新手学习
- guzhigu2013-09-04很不错,合适好好学习下
god_and_donkey
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功