📄 用单片机和点阵图型lcd显示屏制作流动图像(发布).c
字号:
}
//判断X,Y轴并写入一位数据,k=1反显
void LCD_writeAword(unsigned char LCD_store,unsigned char *y,unsigned char k)
{
if(*y==64 || *y==LCD_y)//判断是否要写X,Y轴
{
if(*y>=64)
{
LCD_set_adr(LCD_x,*y-64);
}
else
{
LCD_set_adr(LCD_x,*y);
}
}
if(*y>=64)
{
if(k==0)
{
LCD_wdata(LCD_store,0,1);
}
else
{
LCD_wdata(~LCD_store,0,1);
}
}
else
{
if(k==0)
{
LCD_wdata(LCD_store,1,0);
}
else
{
LCD_wdata(~LCD_store,1,0);
}
}
(*y)++;
}
//a[]数据指针,w宽,h高,move 字节移动,move_little 位移(0-7),head 数据开头指针地址trail 数据最后指针地址,k=1反显
void LCD_write(unsigned char a[],unsigned char w,unsigned char h,signed int move,unsigned char move_little,unsigned int head,unsigned int trail,unsigned char k)
{
unsigned char loop,loop2,y;
unsigned int LCD_store;//临时保存小移数据
signed long word_p;//计数指针
y=LCD_y;
word_p=move*w;
for(loop2=0;loop2<h;loop2++)
{
for (loop=0;loop<w;loop++)
{
if((word_p<0) || word_p>(trail-head+w))
{
LCD_store=0x00;//前面和后面填充
}
else
{
if(move_little==0)
{
LCD_store=a[word_p];
if(word_p>(trail-head))
{
LCD_store=0x00;
}
}
else
{
if(word_p<w)//开头第一行
{
LCD_store=a[word_p]<<move_little;
}
else
{
if(word_p>trail-head)//最后一行
{
LCD_store=a[word_p-w]>>(8-move_little);
}
else
{
LCD_store=a[word_p];//中间
LCD_store=((LCD_store<<8)+a[word_p-w])>>(8-move_little);
}
}
}
}
LCD_writeAword(LCD_store,&y,k);
word_p++;
}
LCD_x++;y=LCD_y;
}
}
//填充子程序
void LCD_write_full(unsigned char d,unsigned char w,unsigned char h)
{
unsigned char loop,loop2,y;
y=LCD_y;
for(loop2=0;loop2<h;loop2++)
{
for(loop=0;loop<w;loop++)
{
if(y==64 || y==LCD_y)//判断是否要写X,Y轴
{
if(y>=64)
{
LCD_set_adr(LCD_x,y-64);
}
else
{
LCD_set_adr(LCD_x,y);
}
}
if(y>=64)
{
LCD_wdata(d,0,1);
}
else
{
LCD_wdata(d,1,0);
}
y++;
}
LCD_x++;y=LCD_y;
}
}
void light_view(void)//LCD扫描
{
LCD_x=0;LCD_y=0;//设光标
if(LCD_move_little>0)
{
LCD_move_little--;
}
else
{
LCD_move_little=7;
if(LCD_move>=(light_data_h))
{
LCD_move=(-8);
}
else
{
LCD_move++;
}
}
LCD_write(light_data,128,8,LCD_move,LCD_move_little,LCD_light_head,LCD_light_trail,0);
}
void code_judge(void)//判断遥控代码
{
code_right=0;
switch(code_tt)
{
case d_on_off:
TR1=~TR1;break;//自动移动
case d_P_sum:
if(time_count<20)
{
time_count++;
}
else
{
time_count=1;
};
break;
case d_P_add:
if(time_count>1)
{
time_count--;
}
else
{
time_count=20;
}
break;
case d_quiet:
LCD_light=~LCD_light;//背光
case d_V_add:
if(LCD_move>=(light_data_h))//移动字幕
{
LCD_move=(-8);
}
else
{
LCD_move++;
}
light_view();
break;
case d_V_sum:
if(LCD_move<=(-8))
{
LCD_move=light_data_h;
}
else
{
LCD_move--;
}
light_view();
break;
}
}
//**********判断代码子程序************
unsigned char d_code(unsigned int t)
{
if(t<=0x480 && t>=0x300)
return 0;
else
{
if(t<=0x8ee && t>=0x700)
return 1;
else
return 0xff;
}
}
//*********** 接收代码中断 ************
void receive_code() interrupt 0 using 1
{
unsigned int temp;
unsigned char dd_code;
if(TR0==0)
{
TH0=TL0=0;
TR0=1;
}
else
{
TR0=0;
temp=(TH0<<8)+TL0;
TH0=TL0=0;
TR0=1;
dd_code=d_code(temp);
if((dd_code==0||dd_code==1) && (code_length!=0))
{
code_t=(code_t<<1)+dd_code;
code_length--;
}
else
code_length=_code_length;
if(code_length==0)
{
code_length=_code_length;
if(code_right==0)
{
code_tt=code_t;
code_right=1;
}
}
}
}
//定时器1,中断,定时
void time1() interrupt 3 using 2
{
time_count2++;
}
void main(void)
{
//********************************
TMOD=0x11; //T0定时方式1,T1定时方式1
IT0=1; //INT0边沿触发
EX0=1; //外部中断0允许
TR0=0; //定时器0计数开关
TR1=1; //定时器1开
ET1=1; //定时器1中断开
EA=1; //打开CPU总中断请求
//*********************************
LCD_reset();//初始化
LCD_light=0;//开背光
LCD_dison_off(1);//开显示
LCD_set_startline(0);//设Z坐标
LCD_x=0;LCD_y=0;//设光标
LCD_write_full(0x00,128,8);
LCD_light_head=&light_data[0];
LCD_light_trail=&light_data[128*light_data_h-1];
while(1)
{
if(code_right==1)
{
EX0=0;
code_judge();
EX0=1;
}
if(time_count2>=time_count)
{
time_count2=0;//延时记录清零
light_view();//扫描
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -