用C语言自造1602中文字库

  • 1.jpg
  • 2.jpg

这个程序里面搭配了火焰检测模块,使用的是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


小编导语:这是刚在深圳认识的一个朋友,做硬件研发的,没想到他也是一个发烧型的DIY。



评 论

e

选择昵称后请轻按空格键

    提 交

    请勿进行人身攻击,谩骂以及任何违法国家相关法律法规的言论。

    信息

    13901

    浏览
    0
    oydean

    作者:oydean

    分享:42

    高骚不止.>>

    关键词:1602中文字库

    猜你会喜欢