历史上的今天
今天是:2025年01月15日(星期三)
2018年01月15日 | icc avr LCD1602显示屏程序
2018-01-15 来源:21IC中国电子网
入口参数说明:
// control port
//#define SET_RS sbi(PORTB,5)
//#define CLR_RS cbi(PORTB,5)
//#define OUT_RS sbi(DDRB,5)
//#define SET_RW sbi(PORTB,6)
//#define CLR_RW cbi(PORTB,6)
//#define OUT_RW sbi(DDRB,6)
//#define SET_E sbi(PORTB,7)
//#define CLR_E cbi(PORTB,7)
//#define OUT_E sbi(DDRB,7)
// data port
//#define SET_D4 sbi(PORTD,4)
//#define CLR_D4 cbi(PORTD,4)
//#define OUT_D4 sbi(DDRD,4)
//#define SET_D5 sbi(PORTD,5)
//#define CLR_D5 cbi(PORTD,5)
//#define OUT_D5 sbi(DDRD,5)
//#define SET_D6 sbi(PORTD,6)
//#define CLR_D6 cbi(PORTD,6)
//#define OUT_D6 sbi(DDRD,6)
//#define SET_D7 sbi(PORTD,7)
//#define CLR_D7 cbi(PORTD,7)
//#define OUT_D7 sbi(DDRD,7)
// busy port
//#define GET_BF gbi(PIND,7)
//#define OUT_BF sbi(DDRD,7)
//#define IN_BF cbi(DDRD,7)
----------------------------------------------------------------------
接口定义:
LCD1602 ATmega16
1.GND -------- GND
2.VCC -------- VCC
3.V0 -------- V0
4.RS -------- 由外部程序定义
5.R/W -------- 由外部程序定义
6.E -------- 由外部程序定义
7.D0 -------- NC
8.D1 -------- NC
9.D2 -------- NC
10.D3 -------- NC
11.D4 -------- 由外部程序定义
12.D5 -------- 由外部程序定义
13.D6 -------- 由外部程序定义
14.D7 -------- 由外部程序定义
15.LED+ -------- VCC
16.LED- -------- GND
说明:
(1)使用ATmega16的7根IO口操作LCD1602
(2)该程序的优点是:7根IO可任意定义,不需分布在固定的一组PORT口上
(3)该程序的缺点是:IO定义的写法较为繁琐
----------------------------------------------------------------------
待定参数说明:
//#define DELAY() {_nop_();_nop_();_nop_();}
----------------------------------------------------------------------
对外变量说明:
----------------------------------------------------------------------
对外函数说明:
----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/
#ifndef LCD1602_H
#define LCD1602_H
#include "D:\ICC_H\CmmICC.H"
/* 待定参数 */
#define DELAY() {NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();}
/* 不考虑移植性的写法 */
//uint8 bdata bdat;
//sbit bdat0=bdat^0;
//sbit bdat1=bdat^1;
//sbit bdat2=bdat^2;
//sbit bdat3=bdat^3;
//sbit bdat4=bdat^4;
//sbit bdat5=bdat^5;
//sbit bdat6=bdat^6;
//sbit bdat7=bdat^7;
/* 考虑移植性的写法 */
uint8 bdat;
#define bdat0 (bdat&0x01)
#define bdat1 (bdat&0x02)
#define bdat2 (bdat&0x04)
#define bdat3 (bdat&0x08)
#define bdat4 (bdat&0x10)
#define bdat5 (bdat&0x20)
#define bdat6 (bdat&0x40)
#define bdat7 (bdat&0x80)
#define CGRAM0 0x00
#define CGRAM1 0x01
#define CGRAM2 0x02
#define CGRAM3 0x03
#define CGRAM4 0x04
#define CGRAM5 0x05
#define CGRAM6 0x06
#define CGRAM7 0x07
#define TRUE 1
#define FALSE 0
bool LCD1602Err = FALSE;
/*--------------------------------------------------------------------
函数名称:LCD1602读读读读读忙~
函数功能:都说是读读读读读忙咯~
注意事项:对于高速CPU,应加延时,好像是废话~
提示说明:无
输 入:
返 回:无
--------------------------------------------------------------------*/
void busy(void)
{
uint16 busyCounter=0;
bool busySta; //用于探测 lcd busy status
IN_BF;
SET_D4;
SET_D5;
SET_D6;
SET_D7;
DELAY();
CLR_RS;
DELAY();
SET_RW;
DELAY();
do
{
SET_E;
DELAY();
/* 这里读取AC4-AC6位及BF的值,程序不需记录AC4-AC6的值,所以不存储 */
busySta=(bool)GET_BF;
CLR_E;
DELAY();
/* 读取 "BUSY"时,"D4-D7"状态可能已经改变,必须再次设为输出"1" */
SET_D4;
SET_D5;
SET_D6;
SET_D7;
DELAY();
SET_E;
DELAY();
/* 这里读取AC0-AC3位的值,程序不需记录AC0-AC3的值,所以不存储 */
CLR_E;
DELAY();
if(busyCounter==1000)
{
LCD1602Err=TRUE; //标识LCD1602错误,方便上缴系统报错
return ; //避免由于LCD1602错误而导致程序阻塞
}
busyCounter++;
}
while(busySta);
LCD1602Err=FALSE;
CLR_E;
OUT_BF;
}
/*--------------------------------------------------------------------
函数名称:LCD1602写操作
史海拾趣
|
Wince下如何使用CreateDIBSection第四个参数返回的指针 我在Wince下打开了一张图片并且成功截取了图片 保存截图 使用CreateDIBSection大概如下(我那个也差不多是这样子,因为程序我没有拿回来): hBitmap=CreateDIBSection(hDc,(BITMAPINFO *)lpImgData,DIB_RGB_COLORS, &n ...… 查看全部问答> |
|
int rc = _sqlite3_open(_T(\"存储卡\\\\123.db\"), &m_db); if ( rc != SQLITE_OK ) { ASSERT(FALSE); } 打开不成功,如果是英文目录就没有问题!… 查看全部问答> |
|
我的6410裸奔已经起来了 牛人给的的一个简单的BOOT 代码已经可以在DDR里面运行 但是我没有设置变量创建的地址在哪 那6410是自动在内部8K的SRAM创建变量呢 等到满了8K ...… 查看全部问答> |
|
最近在搞omap-l138 DDR2驱动,DDR芯片是:FMD4A16LCx–30A,遇到问题卡住了。问题是这样的: 发现DDR在操作时,会刷新数据也会变。 测试伪代码: for(i = 0; i <length;i++) { p = ddr_addrbase ...… 查看全部问答> |
|
为什么我的ADC12MEM0寄存器读出来最大值是255 #include unsigned char i=0,qianwei=0,baiwei=0,shiwei=0,gewei=0; #include \"1602.c\" unsigned int a[32]; unsigned int sum=0; unsigned int temp=0; void main() { &n ...… 查看全部问答> |
|
从单片机到ARM9 参与Helper2416开发板助学计划心得 在ARM9之前学习过51、MSP430、STM32,从8位到16位再到32位的单片机,每一次的跨越无疑都是一次挑战。其中最明显的就是使用单片机实现某一相同的功能需要配置的寄存器越来越多。 ...… 查看全部问答> |




