📄 display.c
字号:
#include "public.h"
volatile uint8_t ramdata;
//const uint8_t day_code[] PROGMEM ="天一二三四五六上下";
//const uint8_t text_calendar[] PROGMEM="20 年 月 日 星期";
const uint8_t button_caption[40] = {"主机\0飞达\0双张\0校屏\0上升\0下降\0复位\0连续"};
const uint8_t action_code[] = {1,2,4,0,0X10,0x20,0X40,8};
const uint8_t point_code[] ={128,64,32,16,8,4,2,1};
const uint8_t pos_clk_scale[] =
{
65,65,64,62,59,56,53,48,
43,38,33,26,20,14,7,0
};
const uint8_t pos_clk_sp[] =
{
60,60,59,57,55,52,49,45,
40,35,30,24,19,12,6,0
};
const uint8_t pos_clk_mp[] =
{
50,50,49,48,46,43,40,37,
33,29,25,20,15,10,5,0
};
const uint8_t pos_clk_hp[] =
{
40,40,39,38,37,35,32,30,
27,24,20,16,12,8,4,0
};
const uint8_t pos_clk_dp[] =
{
10,10,10,9,9,8,8,7,6,5,5,4,3,2,1,10
};
const uint8_t date_x[] ={21,23,26,28,31,33,36};
const uint8_t dn_month[] =
{
31,28,31,30,31,30,31,31,30,31,30,31,
3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5
};
void set_position(uint8_t x,uint8_t y)
{
lcm_reg_write(LCMR_CPXR,x);
lcm_reg_write(LCMR_CPYR,y);
}
void display_rom_string(uint8_t x,uint8_t y,uint16_t str,uint8_t mode)
{
set_text_mode();
set_position(x,y);
lcm_reg_write(LCMR_WCCR,((lcm_reg_read(LCMR_WCCR) & 0X8F) | (mode & (~0x8f)) | 0x08));
mode = *((const uint8_t *)str++);
while(mode)
{
lcm_data_write(mode);
mode = *((const uint8_t *)str++);
}
}
void display_ram_string(uint8_t x,uint8_t y,uint8_t * str,uint8_t mode)
{
set_text_mode();
set_position(x,y);
lcm_reg_write(LCMR_WCCR,((lcm_reg_read(LCMR_WCCR) & 0X8F) | (mode & (~0x8f)) | 0x08));
while(*str)
{
lcm_data_write(*str++);
}
}
void set_active_window(uint8_t x,uint8_t y,uint8_t w,uint8_t h)
{
lcm_reg_write(LCMR_AWRR,x+w-1);
lcm_reg_write(LCMR_AWBR,y+h-1);
lcm_reg_write(LCMR_AWLR,x);
lcm_reg_write(LCMR_AWTR,y);
set_position(x,y);
}
void display_rom_graph(uint8_t x,uint8_t y,uint8_t w,uint8_t h, const uint8_t * graph)
{
uint8_t i;
set_graph_mode();
for(;h;h--)
{
set_position(x,y++);
for(i=w;i;i--)
{
lcm_data_write(*graph++);
}
}
}
void display_position(uint16_t x,uint16_t y)
{
set_text_mode();
lcm_set_1fn();
display_ram_string(0,21," ",0x20);
display_ram_string(10,21," ",0x20);
display_number(7,21,x,1);
display_number(17,21,y,1);
}
void display_cal_number(int32_t n,uint8_t p,uint8_t mem)
{
uint8_t x=31;
uint8_t i;
uint8_t s=0;
if(n<0)
{
n=-n;
s=1;
}
if(!n && (p & 0x80))
{
s=1;
}
p &= 0x03;
p ^= 0x03;
lcm_set_access_layer1();
set_active_window(6,21,31,37);
lcm_clr();
set_text_mode();
//set_position(10,21);
//for(i=10;i;i--)
//{
// lcm_data_write(0x20);
//}
for(i=0;i<3 || n;i++)
{
if(i>=p)
{
set_position(x,21);
lcm_data_write((n % 10)+0x30);
x-=2;
}
n /= 10;
if(i==1)
{
if(p<3)
{
set_position(x,21);
lcm_data_write('.');
x-=2;
}
else
{
p=2;
}
}
}
if(s)
{
set_position(x,21);
lcm_data_write('-');
}
if(mem & 0x40)
{
set_position(6,21);
lcm_data_write('M');
}
}
void display_cal_overflow(void)
{
lcm_set_access_layer1();
set_active_window(5,18,29,40);
lcm_clr();
set_active_window(0,0,39,239);
display_ram_string(17,21,"overflow",0x20);
}
/*void display_main_manu(void)
{
uint8_t x,y;
uint16_t addr=(uint16_t)pic_main_manu;
lcm_set_disp_2layers();
lcm_set_access_2layers();
set_active_window(0,0,40,240);
lcm_clr();
lcm_set_layer_xor();
lcm_set_access_layer2();
x=2;
while(1)
{
y=78;
while(1)
{
display_rom_graph(x,y,16,32,addr);
addr+=512;
y+=58;
if(y>239)
{
break;
}
}
x+=20;
if(x>22)
{
break;
}
}
display_rom_graph(8,10,24,31,(uint16_t)pic_main_title);
fill_block(0,48,40,3,0xff);
fill_block(0,54,40,3,0xff);
}*/
/*void reverse_cal_key(uint8_t n)
{
lcm_set_access_layer1();
uint8_t i=(n & 0x7f);
uint8_t x=5,y=72;
for(;i>5;i-=6)
{
y+=40;
}
for(;i;i--)
{
x+=5;
}
if(n & 0x80)
{
fill_block(x,y,4,32,0xff);
}
else
{
fill_block(x,y,4,32,0x00);
}
}*/
/*void reverse_manu(uint8_t n)
{
lcm_set_access_layer1();
uint8_t i=(n & 0x7f);
uint8_t x,y;
if(i>2)
{
x=22;
i-=3;
}
else
{
x=2;
}
if(!i)
{
y=78;
}
else if(i==1)
{
y=78+58;
}
else
{
y=78+58+58;
}
if(n & 0x80)
{
fill_block(x,y,16,32,0xff);
}
else
{
fill_block(x,y,16,32,0x00);
}
}*/
void display_number(uint8_t x,uint8_t y,uint32_t n,uint8_t step)
{
uint8_t i;
set_text_mode();
set_position(x,y);
x -= step;
if(0 == n)
{
lcm_data_write(0x30);
return;
}
while(1)
{
i = n % 10;
n /= 10;
if((0 == i) && (0 == n))
{
return;
}
lcm_data_write(0x30+i);
set_position(x,y);
x -= step;
}
}
void draw_rectangle(uint8_t x,uint8_t y,uint8_t w,uint8_t h,uint8_t th)
{
uint8_t i;
if(!th)
{
th=1;
}
if(th>8)
{
th=8;
}
if(w<3) return;
if(h<=(th+th)) return;
fill_block(x,y,w,th,0xff);
i=(0xff<<(8-th));
fill_block(x,y+th,1,h-th-th,i);
i=(0xff>>(8-th));
fill_block(x+w-1,y+th,1,h-th-th,i);
fill_block(x,y+h-th,w,th,0xff);
}
void fill_block(uint8_t x,uint8_t y,uint8_t w,uint8_t h,uint8_t fc)
{
uint8_t i;
set_graph_mode();
set_active_window(x,y,w,h);
for(;h;h--)
{
for(i=w;i;i--)
{
lcm_data_write(fc);
}
}
}
void point(uint16_t x,uint8_t y,uint8_t mode)
{
uint8_t tmp;
set_position(x>>3,y);
tmp=lcm_data_read();
if(!mode)
{
tmp &= (~(*((const uint8_t *)point_code+(x & 0x07))));
}
else if(mode==1)
{
tmp |= *((const uint8_t *)point_code+(x & 0x07));
}
else
{
tmp ^= *((const uint8_t *)point_code+(x & 0x07));
}
lcm_data_write(tmp);
}
void line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint8_t mode)
{
uint16_t x,y;
uint16_t dx;// = abs(x1 - x0);
uint16_t dy;// = abs(y1 - y0);
if(y0==y1)
{
if(x0<=x1)
{
x=x0;
}
else
{
x=x1;
x1=x0;
}
while(x <= x1)
{
point(x,y0,mode);
x++;
}
return;
}
else if(y0>y1)
{
dy=y0-y1;
}
else
{
dy=y1-y0;
}
if(x0==x1)
{
if(y0<=y1)
{
y=y0;
}
else
{
y=y1;
y1=y0;
}
while(y <= y1)
{
point(x0,y,mode);
y++;
}
return;
}
else if(x0 > x1)
{
dx=x0-x1;
x = x1;
x1 = x0;
y = y1;
y1 = y0;
}
else
{
dx=x1-x0;
x = x0;
y = y0;
}
if(dx == dy)
{
while(x <= x1)
{
x++;
if(y>y1)
{
y--;
}
else
{
y++;
}
point(x,y,mode);
}
}
else
{
point(x, y, mode);
if(y < y1)
{
if(dx > dy)
{
int16_t p = dy * 2 - dx;
int16_t twoDy = 2 * dy;
int16_t twoDyMinusDx = 2 * (dy - dx);
while(x < x1)
{
x++;
if(p < 0)
{
p += twoDy;
}
else
{
y++;
p += twoDyMinusDx;
}
point(x, y,mode);
}
}
else
{
int16_t p = dx * 2 - dy;
int16_t twoDx = 2 * dx;
int16_t twoDxMinusDy = 2 * (dx - dy);
while(y < y1)
{
y++;
if(p < 0)
{
p += twoDx;
}
else
{
x++;
p+= twoDxMinusDy;
}
point(x, y, mode);
}
}
}
else
{
if(dx > dy)
{
int16_t p = dy * 2 - dx;
int16_t twoDy = 2 * dy;
int16_t twoDyMinusDx = 2 * (dy - dx);
while(x < x1)
{
x++;
if(p < 0)
{
p += twoDy;
}
else
{
y--;
p += twoDyMinusDx;
}
point(x, y,mode);
}
}
else
{
int16_t p = dx * 2 - dy;
int16_t twoDx = 2 * dx;
int16_t twoDxMinusDy = 2 * (dx - dy);
while(y1 < y)
{
y--;
if(p < 0)
{
p += twoDx;
}
else
{
x++;
p+= twoDxMinusDy;
}
point(x, y,mode);
}
}
}
}
}
void rectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint8_t mode,uint8_t fill)
{
if(fill)
{
uint16_t i;
if(x0>x1)
{
i=x1;
x1=x0;
}
else
{
i=x0;
}
for(;i<=x1;i++)
{
line(i,y0,i,y1,mode);
}
return;
}
line(x0,y0,x0,y1,mode);
line(x0,y1,x1,y1,mode);
line(x1,y1,x1,y0,mode);
line(x1,y0,x0,y0,mode);
}
void circle(uint16_t cx,uint16_t cy,uint16_t r,uint8_t mode,uint8_t fill)
{
uint16_t x,y;
int16_t delta,tmp;
x=0;
y=r;
delta=3-(r<<1);
while(y>x)
{
if(fill)
{
line(cx+x,cy+y,cx-x,cy+y,mode);
line(cx+x,cy-y,cx-x,cy-y,mode);
line(cx+y,cy+x,cx-y,cy+x,mode);
line(cx+y,cy-x,cx-y,cy-x,mode);
}
else
{
point(cx+x,cy+y,mode);
point(cx-x,cy+y,mode);
point(cx+x,cy-y,mode);
point(cx-x,cy-y,mode);
point(cx+y,cy+x,mode);
point(cx-y,cy+x,mode);
point(cx+y,cy-x,mode);
point(cx-y,cy-x,mode);
}
x++;
if(delta>=0)
{
y--;
tmp=(x<<2);
tmp-=(y<<2);
delta+=(tmp+10);
}
else
{
delta+=((x<<2)+6);
}
}
}
void pos_pointer(uint8_t * px,uint8_t * py,const uint8_t * tab,uint8_t scale,uint8_t size)
{
uint8_t dx,dy;
if(scale>=60)
{
scale-=60;
}
dy=scale % 15;
dx=*((const uint8_t *)tab+dy);
dy=*((const uint8_t *)tab+size-dy);
if(scale<15)
{
*px=80+dy;
*py=158-dx;
}
else if(scale<30)
{
*px=80+dx;
*py=158+dy;
}
else if(scale<45)
{
*px=80-dy;
*py=158+dx;
}
else
{
*px=80-dx;
*py=158-dy;
}
}
void draw_line_pointer(uint8_t scale,uint8_t mode)
{
uint8_t x,y;
lcm_set_access_layer1();
pos_pointer(&x,&y,pos_clk_sp,scale,15);
line(80,158,x,y,mode);
lcm_set_access_layer2();
}
void draw_tri_pointer(const uint8_t * addr,uint8_t scale,uint8_t mode)
{
uint8_t x,y,x1,y1,x2,y2;
lcm_set_access_layer1();
pos_pointer(&x,&y,addr,scale,15);
pos_pointer(&x1,&y1,pos_clk_dp,scale+37,14);
pos_pointer(&x2,&y2,pos_clk_dp,scale+22,14);
line(x,y,x1,y1,mode);
line(x,y,x2,y2,mode);
line(x1,y1,x2,y2,mode);
}
/*void show_tab(uint8_t tb)
{
uint16_t x = 1;
uint8_t n = tb;
lcm_set_disp_2layers();
lcm_set_access_2layers();
set_active_window(0,0,40,240);
lcm_clr();
lcm_set_layer_xor();
lcm_set_access_layer2();
fill_block(0,0,36,32,0);
while(n--)
{
x+=96;
}
rectangle(x,1,x+93,30,1,0xff);
lcm_set_access_layer1();
display_rom_graph(0,0,36,32,(uint16_t)pic_tab);
if(0 == tb)
{
show_content_main();
}
else if(1 == tb)
{
show_content_eknife();
}
else if(2 == tb)
{
//show_content_message();
}
}*/
void show_logo(void)
{
lcm_set_disp_layer1();
lcm_set_access_layer1();
display_rom_graph(4,89,32,61,pic_grlogo);
}
/*
void show_content_eknife(void)
{
lcm_set_1fn();
uint8_t i,y,mask = 0x10;
display_ram_string(1,44,"刀号 下刀 卡纸 状态",0x20);
for(i=0,y=69; i<5; y+=25,mask>>=1)
{
display_number(9,y,dly_kn[i],1);
display_number(14,y,dly_kn[i+5],1);
set_position(16,y);
lcm_data_write((kn_mask & mask)?'1':'0');
lcm_data_write((kn_error & mask)?'e':'n');
lcm_data_write((kn_jamp & mask)?'j':'n');
i++;
display_number(1,y,i,1);
set_position(2,y);
lcm_data_write('#');
}
lcm_set_graph_mode();
for(y=39;y<190;y+=25)
{
line(4,y,164,y,1);
}
for(y=4;y<165;y+=40)
{
line(y,39,y,189,1);
}
show_button();
show_scom_state();
}
void show_content_main(void)
{
lcm_set_1fn();
display_ram_string(1,44,"总 计 数: 张",0x20);
display_ram_string(1,69,"打包数量: 张",0x20);
display_ram_string(1,94,"打包时间: s",0x20);
display_ram_string(1,119,"吸风延时: ms",0x20);
display_ram_string(1,144,"主机转速: rpm",0x20);
display_ram_string(1,169,"双张检测:",0x20);
display_number(17,44,counter,1);
display_number(17,69,pack_counter,1);
display_number(17,94,pack_timer,1);
display_number(17,119,vac_timer,1);
display_number(16,144,vvvf_rate,1);
display_number(17,169,dpd,1);
lcm_set_graph_mode();
uint8_t y;
for(y=39;y<190;y+=25)
{
line(4,y,164,y,1);
}
line(4,39,4,189,1);
line(164,39,164,189,1);
show_button();
show_scom_state();
}
void refresh_eknife_state(void)
{
uint8_t i,y,mask = 0x10;
lcm_set_text_mode();
lcm_set_1fn();
lcm_set_access_layer1();
for(i=0,y=69; i<5; y+=25,mask>>=1)
{
set_position(16,y);
lcm_data_write((kn_mask & mask)?'1':'0');
lcm_data_write((kn_error & mask)?'e':'n');
lcm_data_write((kn_jamp & mask)?'j':'n');
i++;
}
}
void show_key(uint8_t n,uint8_t reverse)
{
uint8_t x,y,tmp1;
if(n > 11)
{
n = 11;
}
tmp1 = (n & 0x03);
}*/
void show_key_pad(uint8_t n,uint8_t * str)
{
uint8_t i=0,x,y;
lcm_set_access_2layers();
set_active_window(3,40,21,176);
lcm_clr();
lcm_set_access_layer1();
set_active_window(0,0,40,240);
rectangle(24,40,192,216,1,0);
rectangle(32,64,184,104,1,0);
lcm_set_text_mode();
lcm_set_1fn();
if((0x00 != n) && (10>n))
{
set_position(4,44);
lcm_data_write(0x30+n);
lcm_data_write('#');
display_ram_string(6,44,str,0x20);
}
else
{
display_ram_string(4,44,str,0x20);
}
lcm_set_42fn();
for(y=108;y<181;y+=36)
{
for(x=4;x<20;x+=5)
{
uint8_t ch;
if(i<10)
{
ch = i+0x30;
}
else if(i == 10)
{
ch = 'X';
}
else
{
ch = 'V';
}
set_position(x,y);
lcm_data_write(ch);
long_delay(2);
i++;
}
}
}
/*void show_scom_state(void)
{
lcm_set_graph_mode();
rectangle(4,200,312,230,1,0);
display_ram_string(1,207,"通信:主控 电子刀 变频器 双张 ",0x20);
}
void show_button(void)
{
uint16_t x;
uint8_t y;
uint16_t addr = (uint16_t)button_caption;
set_active_window(0,0,40,240);
for(x = 200;x<265;x+=64)
{
for (y = 39;y<170;y+=40)
{
rectangle(x,y,x+47,y+29,1,0);
}
}
for(x = 26;x<35;x += 8)
{
for(y = 46;y<167;y+=40)
{
display_rom_string(x,y,addr,0x20);
addr += 5;
}
}
refresh_main_state();
}
void refresh_main_state(void)
{
uint8_t x,y;
uint16_t addr = (uint16_t)action_code;
set_active_window(0,0,40,240);
lcm_set_access_layer2();
for(x = 25;x<34;x+=8)
{
for (y = 39;y<170;y+=40)
{
fill_block(x,y,6,30,(0x00 != (mn_state & pgm_read_byte(addr++)))?0xff:0);
}
}
lcm_set_access_layer1();
}
*/
/*void refresh_counter(void)
{
lcm_set_1fn();
lcm_set_access_layer1();
display_ram_string(10,44," ",0x20);
display_number(17,44,counter,1);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -