📄 1302disp.c
字号:
#include "config.h"
#include "mb90092.h"
#include "asic.h"
#include "string.h"
//#include "define.h"
//extern void io0_set(uint8 data);
//extern void io0_clr(uint8 data);
//extern void io1_set(uint8 data);
//extern void io1_clr(uint8 data);
/*********************************************************************/
/* 实时时钟模块 时钟芯片型号:DS1302 */
/**/
/*********************************************************************/
#define T_RST 24 /* P3.24 实时时钟复位线引脚 */
#define T_IO 16 /* P1.16 实时时钟数据线引脚 */
#define T_CLK 25 /* P3.25 实时时钟时钟线引脚 */
#define T_IO_SET 0x00010000
#define T_INCON 0xfffeffff /* 定义写端口设置字 */
#define T_OUTCON1 0x00010000 /* 定义读端口设置字 */
#define T_OUTCON3 0x03000000 /* 定义读端口设置字 */
char time_1302_buf[14];
uint8 set_1302_buf[7];
char disp_1302_buf[7];
char time_1302_buf0;
char time_1302_buf1;
char time_1302_buf2;
char time_1302_buf3;
char time_1302_buf4;
char time_1302_buf5;
char time_1302_buf6;
char time_1302_buf7;
char time_1302_buf8;
char time_1302_buf9;
char time_1302_buf10;
char time_1302_buf11;
//#include "sctruct.h"
#define VREST 0x10000000
#define VCS 0x20000000
#define VSCK 0x40000000
#define VSI 0x80000000
char disp_in_use=0;
uint16 _X,_Y;
int8 kkk;
void Hold(uint32 dly) ;
void v_InitDS1302(void);
void v_RTInputByte(uint8 ucDa);
uint8 uc_RTOutputByte(void);
void v_W1302(uint8 ucAddr, uint8 ucDa);
uint8 uc_R1302(uint8 ucAddr);
void v_BurstW1302T(uint8 *pSecDa);
void v_BurstR1302T(uint8 *pSecDa);
void v_Set1302(uint8 *pSecDa);
void v_Get1302(uint8 ucCurtime[]) ;
uint8 set_1302(void);
void DelayNS(uint16 dly)
{ uint16 i;
for(;dly>0;dly--)
for(i=0;i<100;i++);
}
void command(uint16 com)
{
char i,j;
char *p;
uint8 dat;
IO2CLR = VCS; /*使MB90092片选有效*/
DelayNS(10);//for(j=0;j<10;j++){;;}/*延时*/
// p=(char *)&com;
// dat=*p;
dat=(uint8)(com>>8);
for(i=0;i<8;i++)
{
IO2CLR = VSCK;
DelayNS(1);//for(j=0;j<10;j++){;;}/*延时*/
if((dat&0x01)==0)
{IO2CLR=VSI;
DelayNS(1);}
else
{
IO2SET=VSI;
DelayNS(1);
}
dat>>=1;
DelayNS(1);//for(j=0;j<10;j++){;;}/*延时*/
IO2SET=VSCK;
DelayNS(1);//for(j=0;j<1;j++){;;}/*延时*/
}
dat=(uint8)com;
for(i=0;i<8;i++)
{
IO2CLR=VSCK;
DelayNS(1);//for(j=0;j<10;j++){;;}/*延时*/
if((dat&0x01)==0)
{IO2CLR=VSI;
DelayNS(1);
}
else
{
IO2SET=VSI;
DelayNS(1);
}
dat>>=1;
DelayNS(1);//for(j=0;j<10;j++){;;}/*延时*/
IO2SET=VSCK;
DelayNS(1);//for(j=0;j<1;j++){;;}
}
IO2SET=VCS;/*使MB90092片选无效*/
DelayNS(10);//for(j=0;j<10;j++){;;}/*延时*/
}
/*****************************************
MB90092上电复位,上电后MB90092处于复位状态,
SPI口必须要在CS脚给出4次有效后,才可使用
******************************************/
void MB90092_REST(void)
{
//uint8 SFRPAGE_BAK;
uint16 i,j;
DelayNS(100);
IO2CLR=VREST;
DelayNS(100);
IO2SET=VREST;
DelayNS(100);
IO2CLR=VCS;
DelayNS(100);
IO2SET=VCS;
DelayNS(100);
IO2CLR=VCS;
DelayNS(100);
IO2SET=VCS;
DelayNS(100);
IO2CLR=VCS;
DelayNS(100);
IO2SET=VCS;
DelayNS(100);
//3
IO2CLR=VCS;
DelayNS(100);
IO2SET=VCS;
DelayNS(100);
IO2CLR=VCS;
DelayNS(100);
IO2SET=VCS;
DelayNS(100);
//4
DelayNS(1000);
DelayNS(1000);
DelayNS(1000);
}
/*************************************
汉字内码到显示命令码转换
输入为汉字内码,输出为显示命令数据结构
**************************************/
main_char GbToAddress(uint16 gb)
{
uint16 zone;/*区码*/
uint16 site;/*位码*/
uint16 addr;/*字模地址*/
main_char t;
site=gb>>8;
zone=gb&0x00ff;
addr=(zone-0xa1)*94+(site-0xa1);/*计算字模地址*/
t.char_addr2=addr&0x007f;/*取低7位*/
t.char_addr2|=((addr<<1)&0x0700);
t.char_addr1=0;
if((addr&0x1000)!=0)t.char_addr1|=MC;
if((addr&0x0800)!=0)t.char_addr1|=MB;
if((addr&0x0400)!=0)t.char_addr1|=MA;/*完成main charater 2命令*/
return t;
}
/**************************************
主屏显示字符定位,输入X,Y坐标,输出:成功1,失败0
***************************************/
int8 gotoxy(uint16 x,uint16 y)
{
uint16 com;
if((x>0x000f)|(y>0x001f))return 0;
_X=x;_Y=y;
com=VRAM_ADDR_SET;
com|=((_X<<6)&0x0300);
com|=((_X<<5)&0x0060);
com|=_Y;
command(com);
return 1;
}
/**************************************
清屏命令
***************************************/
void cls(void)
{
gotoxy(0,0);
_X=0;_Y=0;
command(VRAM_WRITE_CONTROL|FIL);
command(MAIN_SCREEN_CHAR_CONTROL1/*|MC|MB|MA*/);
command(MAIN_SCREEN_CHAR_CONTROL2/*|M9|M8|M7|M6|M5|M4|M3|M2|M1|M0*/);
command(VRAM_WRITE_CONTROL);
}
/**************************************
扩展方式 在X行,Y列显示1个汉字
输入:汉字内码,字符颜色,字符背景颜色
输出:-1失败,0成功显示,到最后,1成功显示。
***************************************/
int8 putcharex(uint16 x,uint16 y,uint16 gb,uint16 CharColor,uint16 BackColor)
{
if(!gotoxy(x,y))return -1;
command(GbToAddress(gb).char_addr1|CharColor|BackColor|MAIN_SCREEN_CHAR_CONTROL1);
command(GbToAddress(gb).char_addr2|MAIN_SCREEN_CHAR_CONTROL2);
return 1;
}
/**************************************
清一个窗口
***************************************/
int8 cls_windows(char top,char left,char bottom,char right)//reentrant
{
uint16 i,j;
//if(disp_in_use)return -1;
disp_in_use=1;
for(i=top;i<=bottom;i++)
for(j=left;j<=right;j++)
putcharex(i,j,*(int16 *)" ",C_YELLOW,B_GREEN);/*在初始位置显示箭头*/
disp_in_use=0;
return 0;
}
/***************************************
扩展方式输出一串字符
输入X,Y坐标
****************************************/
int8 sprintex(uint16 m_x,uint16 m_y,char*m_s,int16 CharColor,int16 BackColor) //reentrant
{
int16 cnt;
int16 flag;
int16 cnt2;
uint16 x,y;
uint8 iii=0;
char *s;
char i;
// if(disp_in_use)
// return -1;
disp_in_use=1;
cnt=0;
flag=0;
cnt2=0;
x=m_x;
y=m_y;
s=m_s;
//while(*s!='\0')
while(iii<1)
{
if((*s>=0xa1)&&(*(s+1)>=0xa1))/*如果是汉字内码*/
{
flag=putcharex(x,y+cnt,*(int16 *)s,CharColor,BackColor);/*显示一个字符*/
if(flag==-1)
{
disp_in_use=0;
return -1;/*有错误*/
}
if(flag==1)
{
if(y+cnt+1<24)
{
s+=2;
cnt++;
cnt2+=2;
}
else
if(x+1<7)
{
s+=2;
cnt=0;y=0;x++;
cnt2+=2;
}
else
{
disp_in_use=0;
return cnt2;/*显示到最后行列*/
}
}/*正常*/
}
else/*是ASIC码*/
{
if(*s>=32)/*大于32为可显示的ASIC字符*/
{
flag=putcharex(x,y+cnt,*(int16 *)(asic+(*s-32)*2),CharColor,BackColor);/*显示一个字符*/
if(flag==-1)
{
disp_in_use=0;
return -1;/*有错误*/
}
if(flag==1)
{
if(y+cnt+1<24)
{
s+=1;
cnt++;
cnt2+=1;
}
else
if(x+1<7)
{
s+=1;
cnt=0;y=0;x++;
cnt2+=1;
}
else
{
disp_in_use=0;
return cnt2;/*显示到最后行列*/
}
}/*正常*/
}
else
if(*s==13)/*判断是否为回车*/
{
if(x+1<7)
{
s+=1;
cnt=0;y=0;x++;
cnt2+=1;
}
else
{
disp_in_use=0;
return cnt2;/*显示到最后行列*/
}
}
else
if(*s==9)/*判断是否为TAB*/
{
for(i=0;i<4;i++)/*TAB显示4个空格*/
{
flag=putcharex(x,y+cnt,*(int16 *)" ",CharColor,BackColor);/*显示一个字符*/
if(flag==-1)
{
disp_in_use=0;
return -1;/*有错误*/
}
if(flag==1)
{
if((y+cnt+1)<24)cnt++;
else
if((x+1)<7)
{
cnt=0;y=0;x++;
}
else
{
disp_in_use=0;
return cnt2;/*显示到最后行列*/
}
}/*正常*/
}
s+=1;
cnt2+=1;
}
else
{
s+=1;
cnt2+=1;
}
}
iii++;
}
disp_in_use=0;
return 0;/*返回显示的字符数*/
}
/***************************************
扩展方式输出一串字符,用于标题显示
输入X,Y坐标
****************************************/
int8 sprint_title(uint16 x,uint16 y,char *s,uint16 CharColor,uint16 BackColor) //reentrant
{
int16 cnt=0;
int16 flag=0;
int16 cnt2=0;
// if(disp_in_use)return -1;
disp_in_use=1;
while(*s!='\0')
{
if((*s>=0xa1)&&(*(s+1)>=0xa1))/*如果是汉字内码*/
{
flag=putcharex(x,y+cnt,*(int16 *)s,CharColor,BackColor);/*显示一个字符*/
if(flag==-1)
{
disp_in_use=0;
return -1;/*有错误*/
}
if(flag==1)
{
if(y+cnt+1<24)
{
s+=2;
cnt++;
cnt2+=2;
}
else
if(x+1<7)
{
s+=2;
cnt=0;y=0;x++;
cnt2+=2;
}
else
{
disp_in_use=0;
return cnt2;/*显示到最后行列*/
}
}/*正常*/
}
else/*是ASIC码*/
{
if((*s>=32)&&(*s<=128))/*大于等于32并且小于等于asic表长度加32,为可显示的ASIC字符*/
{
flag=putcharex(x,y+cnt,*(int16 *)(asic+(*s-32)*2),CharColor,BackColor);/*显示一个字符*/
if(flag==-1)
{
disp_in_use=0;
return -1;/*有错误*/
}
if(flag==1)
{
if(y+cnt+1<24)
{
s+=1;
cnt++;
cnt2+=1;
}
else
if(x+1<7)
{
s+=1;
cnt=0;y=0;x++;
cnt2+=1;
}
else
{
disp_in_use=0;
return cnt2;/*显示到最后行列*/
}
}/*正常*/
}
else
{
s+=1;
cnt2+=1;
}
}
}
disp_in_use=0;
return 0;/*返回显示的字符数*/
}
/***************************************
扩展方式输出一串字符,用于按键显示
输入X,Y坐标
****************************************/
int8 sprint_key(uint16 x,uint16 y,char *s,uint16 CharColor,uint16 BackColor) //reentrant
{
int16 cnt=0;
int16 flag=0;
// if(disp_in_use)return -1;
disp_in_use=1;
while(*s!='\0')
{
flag=putcharex(x,y+cnt,*(int16 *)s,CharColor,BackColor);/*显示一个字符*/
if(flag==-1)
{
disp_in_use=0;
return -1;/*有错误*/
}
if(flag==1)
{
if(y+cnt+1<24)
{
s+=2;
cnt++;
}
else
if(x+1<8)
{
s+=2;
cnt=0;y=0;x++;
}
else
{
disp_in_use=0;
return 0;/*显示到最后行列*/
}
}/*正常*/
}
disp_in_use=0;
return 0;/*返回显示的字符数*/
}
/**************************************
设置文本方式显示
***************************************/
void set_text(void)
{
command(KANJI_FONT_DISPLAY_CONTROL);
}
/**************************************
设置主屏偏移位置,输入X,Y坐标,输出:成功1,失败0
***************************************/
int8 set_main_position(uint16 x,uint16 y)
{
if((x>0x3f)|(y>0x3f))return 0;
command(MAIN_SCREEN_VERTICAL_POSTION_CONTROL|y);
command(MAIN_SCREEN_HORIZONTAL_POSITION_CONTROL|x|SC);
return 1;
}
/****************************************
开显示
*****************************************/
int8 ondisplay(uint16 backcolor,uint16 alt)
{
if(backcolor>7)return 0;
if((alt!=0)&&(alt!=IE))return 0;
command(SCREEN_CONTROL1|NP|CM|DC|alt);
command(SCREEN_CONTROL2);
command(MAIN_SCREEN_LINE_CONTROL1);
command(MAIN_SCREEN_LINE_CONTROL2|VD);
command(COLOR_CONTROL|RB|CC|BC|UC|backcolor);
return 1;
}
/*uint8 ondisplay(uint16 backcolor,uint16 alt)
{
if(backcolor>7)return 0;
if((alt!=0)&&(alt!=IE))return 0;
command(SCREEN_CONTROL1|NP|CM|DC|alt);
command(SCREEN_CONTROL2|APC);
command(MAIN_SCREEN_LINE_CONTROL1);
command(MAIN_SCREEN_LINE_CONTROL2|VD);
command(COLOR_CONTROL|RB|CC|BC|UC|backcolor);
return 1;
}*/
/****************************************
显示门口图象
*****************************************/
int8 image_alt(uint16 alt)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -