📄 main.c
字号:
#include <MC9S08GB60.h>
#include <hidef.h>
#include "derivative.h"
#include "pub_def.h"
void Wrcomd(UINT8 zoom);//写命令
void Wrdadd(UINT8 zoom);//写地址
void Wrdata(UINT8 zoom);//写数据
void Wrdataloop(UINT8 zoom);//循环写
void Delay1ms(UINT16 j);//1ms延时
void Delay(UINT8 j);
UINT16 i;
UINT8 command;
UINT8 lcdaddr;
UINT8 lcdaddrtemp;
UINT8 lcddata;
UINT8 lcddatatemp;
UINT8 qian,bai,ge,shi;
UINT8 qianH,qianL,baiH,baiL,shiH,shiL,geH,geL;
UINT8 mazhi[10]={0x7D,0x05,0x5B,0x1F,0x27,0x3E,0x7E,0x15,0x7F,0x3F};//码字赋值
//0////1////2/////3///4////5/////6////7////8////9///
void main(void)
{
SOPT = 0x13; //闭关门狗
SPMSC1 = 0x1C;
SPMSC2 = 0x00;
ICGC1 = 0x44;
ICGC2 = 0x00;//FLL处于SCM模式,总线时钟为4MHZ
PTASE = 0x00;
PTBSE = 0x00;
PTCSE = 0x00;
PTDSE = 0x00;
PTESE = 0x00;
PTFSE = 0x00;
PTGSE = 0x00;
PTBD &= (unsigned char)~0x0F; //0111 1111 PTAD6~PTAD0 A B C D E F G
PTBPE &= (unsigned char)~0x0F;
PTBDD |= (unsigned char)0x0F; //0111 1111置为输出模式
PTBD=0x0F;
Delay1ms(500);
Wrcomd(0x29);
Wrcomd(0x18);
Wrcomd(0x01);
Wrcomd(0x03);
//显示第一位
qian=mazhi[8];
qianH=(qian>>4)&0x0F;
qianL=qian&0x0F;
Wrdadd(0x00);
Wrdata(qianH);
Wrdadd(0x04);
Wrdata(qianL);
//显示第二位
bai=mazhi[9];
baiH=(bai>>4)&0x0F;
baiL=bai&0x0F;
Wrdadd(0x08);
Wrdata(baiH);
Wrdadd(0x0C);
Wrdata(baiL);
//显示第三位
shi=mazhi[0];
shiH=((shi>>4)&0x0F)|0x08;
shiL=shi&0x0F;//点亮小数点
Wrdadd(0x10);
Wrdata(shiH);
Wrdadd(0x14);
Wrdata(shiL);
//显示第四位
ge=mazhi[1];
geH=(ge>>4)&0x0F;
geL=ge&0x0F;
Wrdadd(0x18);
Wrdata(geH);
Wrdadd(0x1C);
Wrdata(geL);
}
////////////////////////////////////
///////////////////////////////////
void Wrcomd(UINT8 zoom)//写命令
{
UINT8 i;
PTBD_PTBD0=1;
Delay(1);
PTBD_PTBD0=0;
Delay(1);
PTBD_PTBD1=0;
Delay(1);
PTBD_PTBD2=1;
Delay(1);
PTBD_PTBD1=1;
Delay(1);
PTBD_PTBD1=0;
Delay(1);
PTBD_PTBD2=0;
Delay(1);
PTBD_PTBD1=1;
Delay(1);
PTBD_PTBD1=0;
Delay(1);
PTBD_PTBD2=0;
Delay(1);
PTBD_PTBD1=1;
Delay(1);
for(i=0;i<9;i++)
{
Delay(1);
PTBD_PTBD1=0;
Delay(1);
if(zoom&0x80)
{
PTBD_PTBD2=1;
} else{ PTBD_PTBD2=0;}
Delay(1);
PTBD_PTBD1=1;
Delay(1);
zoom=zoom<<1;
}
}
void Wrdadd(UINT8 zoom)//写地址
{
UINT8 i;
PTBD_PTBD0=1;
Delay(1);
PTBD_PTBD0=0;
Delay(1);
PTBD_PTBD1=0;
Delay(1);
PTBD_PTBD2=1;
Delay(1);
PTBD_PTBD1=1;
Delay(1);
PTBD_PTBD1=0;
Delay(1);
PTBD_PTBD2=0;
Delay(1);
PTBD_PTBD1=1;
Delay(1);
PTBD_PTBD1=0;
Delay(1);
PTBD_PTBD2=1;
Delay(1);
PTBD_PTBD1=1;
Delay(1);
for(i=0;i<6;i++)
{
Delay(1);
PTBD_PTBD1=0;
Delay(1);
if(zoom&0x80)
{
PTBD_PTBD2=1;
} else{ PTBD_PTBD2=0;}
Delay(1);
PTBD_PTBD1=1;
Delay(1);
zoom=zoom<<1;
}
}
void Wrdata(UINT8 zoom)//写数据
{
UINT8 i;
for(i=0;i<4;i++)
{
Delay(1);
PTBD_PTBD1=0;
Delay(1);
if(zoom&0x01)
{
PTBD_PTBD2=1;
} else{ PTBD_PTBD2=0;}
Delay(1);
PTBD_PTBD1=1;
Delay(1);
zoom=zoom>>1;
}
}
void Wrdataloop(UINT8 zoom)//循环写
{
UINT8 y;
UINT8 add=zoom;
for(y=0;y<32;y++)
{
Wrdadd(zoom);
Wrdata(0x0F);
add=add+0x04;
}
}
void Delay1ms(UINT8 j)//j=1 delay 1ms
{
UINT16 k;
for(k=0;k<j;k++)
{
for(i=0;i<96;i++);
}
}
void Delay(UINT8 j)
{
UINT8 k;
for(k=0;k<j;k++)
{
for(i=0;i<5;i++);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -