📄 main1.c
字号:
#include<htc.h>
#include "pic16f887.h"
#define E RA2
#define RW RA1
#define RS RA0
#define LCDVSW RE0
#define LEDCON RC5
#define CS1 RA3
#define CS2 RA4
#define uint unsigned int
#define uchar unsigned char
void lcd_writecom(char com);
void delay(char z);
void delay2(int y);
void init(void);
void onoff(char onoff);
void check_busy(void);
void prl0(uchar com1);
void prr0(uchar com2);
void clsr(void);
void allon(void);
void lcd_writedate(char date);
void show16(void);
void show816(void);
unsigned char page,line,m,l ;
//m 行 L 列
char i,j=0 ;
const char table[]=
{
0x10,0x90,0xFF,0x50,0x90,0x08,0x08,0xE8,0x29,0x2E,0xE8,0x08,0x0C,0x08,0x00,0x00,
0x06,0x01,0x3F,0x00,0x20,0x11,0x08,0x07,0x00,0x00,0x1F,0x20,0x20,0x38,0x00,0x00
}
;
const char table2[]=
{
0x00,0x80,0x60,0x00,0xFF,0x20,0xC0,0x00,0xFE,0x20,0xC0,0x00,0xFE,0x00,0x00,0x00,
0x20,0x10,0x08,0x06,0x01,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x3F,0x00,0x00,0x00
}
;
const char table3[]=
{
0x40,0x30,0x92,0x96,0x9A,0xD2,0x96,0x9A,0x92,0x91,0x99,0xD5,0xB0,0x10,0x00,0x00,
0x00,0x20,0x10,0x28,0x24,0x23,0x16,0x0A,0x0A,0x16,0x22,0x20,0x20,0x00,0x00,0x00
}
;
const char table4[]=
{
0x10,0x4C,0x54,0xD4,0xD4,0x7C,0x55,0x56,0x7C,0xD4,0xD4,0x54,0x4C,0x00,0x00,0x00,
0x02,0x22,0x21,0x20,0x2F,0x11,0x0F,0x09,0x11,0x2F,0x20,0x21,0x02,0x02,0x00,0x00
}
;
const char table5[]=
{
0x10,0x88,0xC4,0x33,0x04,0x74,0x54,0x74,0x5F,0x54,0x74,0x54,0x76,0x04,0x00,0x00,
0x01,0x00,0x3F,0x00,0x1D,0x01,0x1D,0x21,0x23,0x2D,0x21,0x31,0x05,0x19,0x00,0x00
}
;
const char table6[]=
{
0x14,0x14,0x94,0xFE,0x93,0x12,0x00,0x20,0xC4,0x18,0x00,0xFF,0x00,0x00,0x00,0x00,
0x04,0x03,0x00,0x3F,0x00,0x01,0x02,0x02,0x02,0x02,0x02,0x3F,0x01,0x01,0x00,0x00
}
;
const char table7[]=
{
0x08,0x08,0x88,0xFF,0x48,0x00,0x48,0xC8,0x48,0x7F,0x48,0x48,0xCC,0x08,0x00,0x00,
0x01,0x11,0x20,0x1F,0x00,0x20,0x20,0x11,0x0A,0x04,0x0A,0x11,0x20,0x20,0x00,0x00
}
;
const char table8[]=
{
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00
}
;
//***********************************************
//主程序
//***********************************************
void main(void)
{
uchar a ;
// uchar i,j;
init();
delay2(10);
onoff(1);
onoff(0);
onoff(1);
onoff(0);
onoff(1);
do
{
clsr();
delay2(1);
allon();
delay2(1);
show16();
clsr();
show816();
clsr();
}
while(1);
}
void delay(char z)
{
unsigned int x,y ;
for(x=z;x>0;x--)
for(y=5;y>0;y--);
}
void delay2(int y)
{
unsigned int h,j ;
for(h=y;h>0;h--)
for(j=50;j>0;j--);
}
void init(void)
{
ANSELH=0X00 ;
ANSEL=0X00 ;
ADCON0=0x00 ;
ADCON1=0x00 ;
INTCON=0x00 ;
TRISA=0x00 ;
TRISE0=0 ;
LCDVSW=1 ;
LEDCON=1 ;
PIE1=0 ;
PIE2=0 ;
m=0x00 ;
l=0x00 ;
}
void onoff(char onoff)
{
CS1=0 ;
CS2=1 ;
onoff=onoff|0x3e ;
lcd_writecom(onoff);
CS1=1 ;
CS2=0 ;
onoff=onoff|0x3e ;
lcd_writecom(onoff);
}
//**************************************************
void check_busy(void)
{
TRISD=0xff ;
PORTD=0xff ;
RS=0 ;
RW=1 ;
while(1)
{
NOP();
NOP();
NOP();
E=1 ;
NOP();
NOP();
NOP();
if(RD7==0)break ;
NOP();
NOP();
NOP();
E=0 ;
}
E=0 ;
TRISD=0X00 ;
RE2=!RE2 ;
delay(1);
}
void lcd_writecom(char com)
{
check_busy();
RW=0 ;
RS=0 ;
PORTD=com ;
E=1 ;
delay(1);
E=0 ;
}
void lcd_writedate(char date)
{
check_busy();
RW=0 ;
RS=1 ;
PORTD=date ;
E=1 ;
delay(1);
E=0 ;
}
//**************************************************
// 写指令代码子程序(左)
void prl0(uchar com1)
{
CS1=1 ;
CS2=0 ;
lcd_writecom(com1);
}
//**************************************************
// 写指令代码子程序(右)
void prr0(uchar com2)
{
CS1=0 ;
CS2=1 ;
lcd_writecom(com2);
}
//**************************************************
// 写显示数据子程序(左)
void prl1(char dat1)
{
CS1=1 ;
CS2=0 ;
lcd_writedate(dat1);
}
//*************************************************
// 写显示数据子程序(右)
void prr1(char dat2)
{
CS1=0 ;
CS2=1 ;
lcd_writedate(dat2);
}
//**********************************************
//清屏
void clsr(void)
{
uchar i,j ;
// CS1=0 ;
// CS2=1 ;
for(i=0;i<8;i++)
{
prl0(i|0xb8);
//X页地址
//设置页地址
prr0(i|0xb8);
prl0(0x40);
//Y地址
prr0(0x40);
//设置列地址
for(j=0;j<64;j++)
{
prl1(0x00);
//写0x00
prr1(0x00);
}
}
}
//**********************************************
//满屏
void allon(void)
{
uchar i,j ;
// CS1=0 ;
// CS2=1 ;
for(i=0;i<8;i++)
{
prl0(i|0xb8);
//x页地址
prr0(i|0xb8);
prl0(0x40);
//Y地址
prr0(0x40);
for(j=0;j<64;j++)
{
prl1(0xff);
//写0xff
prr1(0xff);
}
}
}
void show16(void)
{
CS1=1 ;
CS2=0 ;
line=96 ;
page=186 ;
lcd_writecom(page);
lcd_writecom(line);
for(i=0;i<16;i++)
lcd_writedate(table[i]);
lcd_writecom(page+1);
lcd_writecom(line);
for(i=16;i<32;i++)
lcd_writedate(table[i]);
line=line+16 ;
lcd_writecom(page);
lcd_writecom(line);
for(i=0;i<16;i++)
lcd_writedate(table2[i]);
lcd_writecom(page+1);
lcd_writecom(line);
for(i=16;i<32;i++)
lcd_writedate(table2[i]);
CS1=0 ;
CS2=1 ;
line=64 ;
lcd_writecom(page);
lcd_writecom(line);
for(i=0;i<16;i++)
lcd_writedate(table3[i]);
lcd_writecom(page+1);
lcd_writecom(line);
for(i=16;i<32;i++)
lcd_writedate(table3[i]);
line=line+16 ;
lcd_writecom(page);
lcd_writecom(line);
for(i=0;i<16;i++)
lcd_writedate(table4[i]);
lcd_writecom(page+1);
lcd_writecom(line);
for(i=16;i<32;i++)
lcd_writedate(table4[i]);
page=188 ;
CS1=1 ;
CS2=0 ;
line=96 ;
lcd_writecom(page);
lcd_writecom(line);
for(i=0;i<16;i++)
lcd_writedate(table5[i]);
lcd_writecom(page+1);
lcd_writecom(line);
for(i=16;i<32;i++)
lcd_writedate(table5[i]);
line=line+16 ;
lcd_writecom(page);
lcd_writecom(line);
for(i=0;i<16;i++)
lcd_writedate(table6[i]);
lcd_writecom(page+1);
lcd_writecom(line);
for(i=16;i<32;i++)
lcd_writedate(table6[i]);
CS1=0 ;
CS2=1 ;
line=64 ;
lcd_writecom(page);
lcd_writecom(line);
for(i=0;i<16;i++)
lcd_writedate(table7[i]);
lcd_writecom(page+1);
lcd_writecom(line);
for(i=16;i<32;i++)
lcd_writedate(table7[i]);
}
void show816(void)
{
char g,h,k ;
k=0 ;
line=0X50 ;
// line=80 ;
// page=184 ;
page=0XB8 ;
for(h=10;h>0;h--)
{
CS1=0 ;
CS2=1 ;
lcd_writecom(page);
lcd_writecom(line);
for(g=0;g<8;g++)
{
lcd_writedate(table8[k]);
k++;
}
lcd_writecom(page+1);
lcd_writecom(line);
for(g=8;g<16;g++)
{
lcd_writedate(table8[k]);
k++;
}
if(k==0xa0)
{
k=0 ;
//line=72 ;
line=72 ;
//0X48
page=0XB8 ;
CS1=0 ;
CS2=1 ;
lcd_writecom(page);
lcd_writecom(line);
for(g=0;g<8;g++)
{
lcd_writedate(table8[m]);
k++;
m++;
}
lcd_writecom(page+1);
lcd_writecom(line);
for(g=8;g<16;g++)
{
lcd_writedate(table8[m]);
k++;
m++;
}
if(m==0xa0)
{
m=0x00 ;
line=64 ;
page=184 ;
lcd_writecom(page);
lcd_writecom(line);
for(g=0;g<8;g++)
{
lcd_writedate(table8[l]);
l++;
m++;
}
lcd_writecom(page+1);
lcd_writecom(line);
for(g=8;g<16;g++)
{
lcd_writedate(table8[l]);
l++;
m++;
}
}
}
delay2(50);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -