用C语言自造LCD1602中文库
来源:互联网 发布:淘宝代购化妆品真假 编辑:程序博客网 时间:2024/06/12 01:05
这个程序里面搭配了火焰检测模块,使用的是ADC0,AD转换,显示的电压值可以根据光谱亮度进行变动。网上的1602字库,大多用汇编语言编写,可移植性太低。我这个是用C语言编写的。1602的字库,你们可以看到,显示了中文“月”与“工”。
#include "iom16v.h"
#include "macros.h"
#include "led.h"
#define uint unsigned int
#define uchar unsigned char
#define D0 PORTD=PORTD&0xbf;
#define D1 PORTD=PORTD|0x40;
unsigned char const lcd1602[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
unsigned char const lcd1602_yue[]={0x0e,0x0a,0x0e,0x0a,0x0e,0x0a,0x12,0x00};
unsigned char const lcd1602_gong[]={0x1f,0x04,0x04,0x04,0x04,0x04,0x1f,0x00};
uint constant1=0,a1=0,a2=0,a3=0,a4=0;
void add_gong() //自造字库“工”
{
int a,b;
for (a=0x48;a<=0x4f;a++)
{
PORTB=a;
enable_lcd();
b=a&0x07;
PORTB=lcd1602_gong[b];
data();
}
}
void add_yue() //自造字库“月”
{
int a=0x40,b;
for (a=0x40;a<0x48;a++)
{
PORTB=a;
enable_lcd();
b=a&0x0f;
PORTB=lcd1602_yue[b];
data();
}
}
void delay(unsigned long a)
{
while(a--);
}
void enable_lcd()
{
PORTD=PORTD&0xcf;
D0;
delay(400);
D1;
}
void data()
{
PORTD=PORTD&0xdf;
PORTD|=0x10;
D0;
delay(400);
D1;
}
void initial()
{
DDRA&=0xfe;//PA0设置为输入 ADC0输入部分
DDRA|=0x40;
PORTA|=0x40;
DDRD|=0x70;//PD4-6设置为输出 1602显示部分 不许改动
D1;
DDRB=0xff;//PB0-7设置为输出 1602显示部分
}
void displayinitial()
{
PORTB=0x00;//清显示
enable_lcd();
PORTB=0x06;//光标右移
enable_lcd();
PORTB=0x10;;//移动光标
enable_lcd();
PORTB=0x38;//4位总线,双行显示,5X7点阵字符
enable_lcd();
PORTB=0x80;//显示从第一行第二个开始
enable_lcd();
PORTB=0x0C;//开显示
enable_lcd();
}
void display1()
{
PORTB=0x80;
enable_lcd();
PORTB='V';
data();
PORTB='o';
data();
PORTB='l';
data();
PORTB='t';
data();
PORTB='a';
data();
PORTB='g';
data();
PORTB='e';
data();
PORTB=':';
data();
PORTB=lcd1602[a1];
data();
PORTB='.';
data();
PORTB=lcd1602[a2];
data();
PORTB=lcd1602[a3];
data();
PORTB=lcd1602[a4];
data();
PORTB='V';
data();
PORTB=0x00;
data();
PORTB=0x01;
data();
}
unsigned int adc()
{
uint a,b;
ADMUX=0x40;//内部REF关闭,直接使用外接的REF,右对齐,选择ADC0
ADCSRA=0xd8;//ADC使能,ADC开始转换,ADIF置位1,ADIE使能,2分频
do
{
;
}
while(ADCSRA&0x10!=0);
a=ADCL;
b=ADCH&0x03;
a=a+b*256;
return a;
}
void main()
{
unsigned int a;
initial();
displayinitial();
add_yue();
add_gong();
display1();
display(0);
strobe(5);
while(1)
{
a=adc();
constant1=a*4.98/1024*1000;
a1=constant1/1000;
a2=constant1%1000/100;
a3=constant1%1000%100/10;
a4=constant1%10;
display1();
delay(1000);
display(a2);
if (constant1<2460) PORTA&=0xbf;
else PORTA|=0x40;
}
}
自造字库,是安插在程序中,感兴趣的朋友,可以研究下。有不明白的地方,欢迎加我QQ:271715999
- 用C语言自造LCD1602中文库
- LCD1602 C语言驱动程序
- C语言程序>>LCD1602
- lcd1602.c
- LCD1602.c
- C语言算法Baidu文库杂集
- C语言中自增符号
- 关于C语言中自增自减
- LCD1602,显示自编译字符
- C语言中关于自加的几个小题
- C语言中结构体 自引用 和 相互引用
- C语言中自增运算符的解析
- C语言中结构体 自引用 和 相互引用
- C语言中结构体 自引用 和 相互引用
- C语言中库函数自带的排序函数qsort
- C语言中库函数自带的查找函数bsearch
- C语言中结构体 自引用 和 相互引用
- C语言中指针的自增运算总结
- 机器时代来临了
- [leetcode] Remove Duplicates from Sorted List II
- VS2010下运行:fatal error C1083: 无法打开包括文件:“opencv.hpp”: No such file or directory
- 文件比较. 写一个比较两个文本文件的程序. 如果不同, 给出第一个不同处的行号和 列号.
- 颜色配置,使用eclipse保护眼睛的秘诀,更改字体大小
- 用C语言自造LCD1602中文库
- Session的生命周期
- Mybatis拦截器介绍及分页插件
- C语言实现面向对象
- java设计模式二(简单工厂模式)
- [leetcode] Largest Rectangle in Histogram——惊天动地的代码@
- hdu 3952
- 明智而审慎的使用private继承
- SQL Server中查找包含某个文本的存储过程