📄 avr128-lcd-display.txt
字号:
#include <iom128v.h>
#ifndef __szs_h
#define __szs_h
#define up k==22
#define down k==23
#define lift k==15
#define right k==31
#define set k==30
#define enter k==7
#define num ((k==4)||(k==12)||(k==20)||(k==28)||(k==5)||(k==13)||(k==21)||(k==29)||(k==6)||(k==14))
#define req asm("sbi 0x03,6")
#define cl_req asm("cbi 0x03,6")
#define dat asm("sbi 0x18,0")
#define cl_dat asm("cbi 0x18,0")
#define cl_reset asm("cbi 0x15,3")
#define set_reset asm("sbi 0x15,3")
#define LCD 0x9000
void delay (unsigned int t)
{
unsigned char i;
for (i=1;i<t;i++);
}
void delay_1ms(void)
{
unsigned int i;
for (i=0;i<2286;i++);
}
void delay_nms(unsigned int n)
{ unsigned int i=0;
for (i=0;i<n;i++)
delay_1ms();
}
void lcd_w(unsigned char data)
{
unsigned char *p=(unsigned char *)(LCD);
while((PINE&0x80)!=0x00)
;
dat;
*p=data;
cl_dat;
;;
req;
;;
while((PINE&0x80)==0x00)
;
cl_req;
}
void lcd_init (void)
{
MCUCR=MCUCR|0x80;
DDRB|=0x01;
PORTB&=0xfe;
DDRE=0x40;
PORTE=0xff;
cl_reset;
delay(10);
set_reset;
delay(10);
cl_req;
delay(10);
}
void lcd_clear (void)
{
lcd_w(0xf4);
}
void lcd_putsc (unsigned char x,unsigned char y,unsigned char *ch)
{
x+=2;
while (*ch!=0)
{
lcd_w(0xf0);
lcd_w(x);
lcd_w(y);
lcd_w(*ch-0xa0);
ch++;
lcd_w(*ch-0xa0);
ch++;
if (x>=0x09)
{
x=2;
y+=1;
}
else
x++;
}
}
void lcd_putse (unsigned char x,unsigned char y,unsigned char *ch)
{
x+=4;
while (*ch!=0)
{
lcd_w(0xf1);
lcd_w(x);
lcd_w(y);
lcd_w(*ch);
ch++;
if (x>=19)
{
x=4;
y+=8;
}
else
x++;
}
}
void lcd_putss (unsigned char x,unsigned char y,unsigned char ch)
{
x+=4;
lcd_w(0xf1);
lcd_w(x);
lcd_w(y);
lcd_w(ch);
}
#define key (PIND&0x08)==0
#define data (PIND&0x04)==0x04
#define set_cs asm("sbi 0x18,2")
#define set_clk asm("sbi 0x18,3")
#define set_data asm("sbi 0x12,2")
#define cl_cs asm("cbi 0x18,2")
#define cl_clk asm("cbi 0x18,3")
#define cl_data asm("cbi 0x12,2")
void init_7279()
{
SREG|=0x80;
EIMSK|=0x08;
EICRA&=0x3f;
DDRD&=0xf7;
DDRB|=0x0c;
PORTB&=0x7f;
PORTB|=0x40;
PORTD&=0xfb;
}
void send (unsigned char out_data)
{
unsigned char i;
DDRD|=0x04;
cl_cs;
l_delay();
for(i=0;i<8;i++)
{
if(out_data&0x80)
{
set_data;
}
else
{
cl_data;
}
s_delay();
set_clk;
s_delay();
cl_clk;
s_delay();
out_data*=2;
}
cl_data;
}
unsigned char receive(void)
{
unsigned char i;
unsigned char in_data=0x00;
DDRD&=0xfb;
for(i=0;i<8;i++)
{
set_clk;
s_delay();
in_data*=2;
if(data)
{
in_data|=0x01;
}
cl_clk;
s_delay();
}
cl_data;
return(in_data);
}
void l_delay()
{
unsigned char i=33;
while(i!=0)
{i--;}
}
void s_delay()
{
unsigned char i=11;
while(i!=0)
{i--;}
}
#endif
#include<iom128v.h>
#include<szs.h>
#pragma interrupt_handler key_check:5
unsigned int j=0;
unsigned int i=0;
unsigned char x=11,y=28,k;
unsigned char m10[7]={58,48,48,48,48,48,0},m11[]={58,54,53,53,51,53,0};
unsigned char m20[7]={58,48,48,48,48,48,0},m21[]={58,54,53,53,51,53,0};
unsigned char m30[7]={58,48,48,48,48,48,0},m31[]={58,54,53,53,51,53,0};
unsigned char m40[7]={58,48,48,48,48,48,0},m41[]={58,54,53,53,51,53,0};
unsigned char m5[7]={58,54,53,53,51,51,0};
unsigned char m6[7]={58,54,53,53,51,48,0};
unsigned char m7[]={50,48,48,56,45,48,56,45,49,50,0};
unsigned char m8[]={48,48,58,48,48,58,48,48,0};
unsigned char m9[]={58,54,53,53,51,53,0};
int h1=0,h2=0,h3=0;
int bz=0;
void delay_nms0(unsigned int n)
{ unsigned int i=0;
for (i=0;i<n;i++)
{delay_1ms();if(bz)return;}
}
void hm0(void){
lcd_clear();
lcd_putsc(0,1,"计数当前值");
lcd_putsc(0,2,"计数上限");
lcd_putse(10,21,m10);
lcd_putse(10,37,m11);
}
void hm1(void){
lcd_clear();
lcd_putsc(0,1,"单位脉冲");
lcd_putsc(0,2,"喷印间距");
lcd_putse(10,21,m20);
lcd_putse(10,37,m21);
}
void hm2(void){
lcd_clear();
lcd_putsc(0,1,"首字段位数");
lcd_putsc(0,2,"次字段位数");
lcd_putse(10,21,m30);
lcd_putse(10,37,m31);
}
void hm3(void){
lcd_clear();
lcd_putsc(0,1,"小数位数");
lcd_putsc(0,2,"公英制转换");
lcd_putse(10,21,m40);
lcd_putse(10,37,m41);
}
void hm4(void){
lcd_clear();
lcd_putsc(0,0,"公英制同时喷印");
lcd_putsc(1,1,"选择");
lcd_putsc(1,2,"取消");
lcd_putss(6,21,58);
lcd_putss(7,21,131);
lcd_putss(6,37,58);
lcd_putss(7,37,130);
if(!h1){lcd_putss(1,21,132);lcd_putss(1,37,32);}
else {lcd_putss(1,37,132);lcd_putss(1,21,32);}
}
void hm5(void){
lcd_clear();
lcd_putsc(0,0,"喷印格式");
lcd_putsc(1,1,"米");
lcd_putsc(3,1,"英尺");
lcd_putsc(1,2,"英尺");
lcd_putsc(4,2,"米");
lcd_putss(5,21,92);
lcd_putss(7,37,92);
lcd_putss(10,21,58);
lcd_putss(11,21,131);
lcd_putss(10,37,58);
lcd_putss(11,37,130);
if(!h2){lcd_putss(1,21,132);lcd_putss(1,37,32);}
else {lcd_putss(1,37,132);lcd_putss(1,21,32);}
}
void hm6(void){
lcd_clear();
lcd_putsc(0,1,"波特率");
lcd_putse(8,7,m6);
lcd_putse(8,21,m5);
lcd_putse(8,35,m9);
switch(h3)
{case 0:lcd_putss(7,7,132);
lcd_putss(7,21,32);
lcd_putss(7,37,32);break;
case 1:lcd_putss(7,7,32);
lcd_putss(7,21,132);
lcd_putss(7,37,32);break;
case 2:lcd_putss(7,7,32);
lcd_putss(7,21,32);
lcd_putss(7,37,132);break;
}
}
void hm7(void){
lcd_clear();
lcd_putsc(0,1,"时间");
lcd_putsc(0,2,"日期");
lcd_putse(5,20,m8);
lcd_putse(5,35,m7);
}
void key_check(){
send(0x15);
k=receive();
set_cs;
delay_nms(20);
bz=1;
}
void p(){
switch(i){
lcd_clear();
case(1):hm0();break;
case(2):hm1();break;
case(3):hm2();break;
case(4):hm3();break;
case(5):hm4();break;
case(6):hm5();break;
case(7):hm6();break;
case(8):hm7();break;
}
}
unsigned char num_get()
{unsigned char a;
if(k%4==0)
a=48+(k-4)/8;
if(k%4==1)
a=52+(k-4)/8;
if(k%4==2)
a=56+(k-4)/8;
lcd_putss(0,0,a);
return a;
}
void guangbiao(){
lcd_putss(x,y,45);
if(lift&&(x>11)){
lcd_putss(x,y,32);
x--;
lcd_putss(x,y,45);
}
if(right&&(x<15)){
lcd_putss(x,y,32);
x++;
lcd_putss(x,y,45);
}
if(up&&y==44){
lcd_putss(x,y,32);
y-=16;
lcd_putss(x,y,45);
}
if(down&&y==28){
lcd_putss(x,y,32);
y+=16;
lcd_putss(x,y,45);
}
if(num)
{switch(i){
case 1: if(y==28) m10[x-10]=num_get();
if(y==44) m11[x-10]=num_get();break;
case 2: if(y==28) m20[x-10]=num_get();
if(y==44) m21[x-10]=num_get();break;
case 3: if(y==28) m30[x-10]=num_get();
if(y==44) m31[x-10]=num_get();break;
case 4: if(y==28) m40[x-10]=num_get();
if(y==44) m41[x-10]=num_get();break;
}
p();
if(x<15) {lcd_putss(x,y,32);
x++;
lcd_putss(x,y,45);}
if(x==15){lcd_putss(x,y,45);}
}
}
void set_p567()
{ if(i==5)
{if(up) h1=0;
if(down)h1=1;
}
if(i==6)
{if(up) h2=0;
if(down)h2=1;
}
if(i==7)
{if(up&&h3>0)h3--;
if(down&&h3<2)h3++;
}
}
void main()
{
lcd_init();
init_7279();
lcd_clear();
lcd_putsc(0,1,"实验室作业");
while(1){
while(bz){
if(set&&i>=1) j=1;
if(enter){j=0;lcd_putss(x,y,32);}
if(!j){
if(up&&i>1){i--;p();x=11;y=28;}
if(down&&i<8){i++;p();x=11;y=28;}
}
if(j&&(i<=4)){guangbiao();}
if(j&&i>=5&&i<=7){set_p567();p();}
bz=0;}
if(j&&i>=5&&i<=7){
if(j&&i>=5&&i<=6){lcd_putss(1,21,32);lcd_putss(1,37,32);}
if(j&&i==7){lcd_putss(7,7,32);
lcd_putss(7,21,32);lcd_putss(7,37,32);}
delay_nms0(50); p();delay_nms0(50);}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -