📄 scan.c
字号:
#include <ht46r62.h>
#pragma rambank0
bit direction;
unsigned char lamp;
unsigned char *p;
unsigned char adcurrent;
//unsigned char t;
const char currentshow[10]=
{0x05f,0x050,0x03d,0x79,0x72,0x6b,0x6f,0x51,0x7f,0x7b};
const char currentvalue[88]=
{ 0x1,0x1,0x1,0x2,0x2,0x3,0x3,0x3,0x4,0x4,0x4,
0x5,0x5,0x6,0x6,0x6,0x7,0x7,0x8,0x8,0x8,
0x9,0x9,0x10,0x10,0x10,0x11,0x11,0x12,0x12,0x12,
0x13,0x13,0x14,0x14,0x14,0x15,0x15,0x16,0x16,0x16,
0x17,0x17,0x18,0x18,0x18,0x19,0x19,0x20,0x20,0x20,
0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x24,0x24,0x24,
0x25,0x25,0x26,0x26,0x26,0x27,0x27,0x28,0x28,0x28,
0x29,0x29,0x30,0x30,0x30,0x31,0x31,0x32,0x32,0x32,
0x33,0x33,0x34,0x34,0x35,0x35,0x35
};
#pragma vector isr_4 @ 0x4
#pragma vector isr_8 @ 0x8
#pragma vector isr_c @ 0xc
#pragma vector isr_14 @ 0x14
//ISR for safequard
//void isr_4(){} // external ISR
void isr_8(){} // timer/event 0
void isr_c(){} // timer/event 1
void isr_14(){_nop();
_nop();
_nop();}
//initialize registers for safeguard
void safeguard_init()
{
_intc0 = 0;
_tmrc = 0;
_tmr = 0;
_pac = 0xff; //input mode
_pbc = 0xff;
//_pcc = 0xff;
}
void io_init()
{
_pac=0x08;
_pa=0x0;
_pbc=0xff;
_pb=0xff;
_pdc=0x00;
_pd=0x0;
}
void int_init()
{ _emi=1;
_eei0=1;
}
void timer_base_interrupt()
{_rtcc=0x0a;
_emi=1;
_erti=1;
_acsr=0x00;
}
char ad_converter()
{
_adcr=0x020;
_start=0;
_start=1;
_start=0;
while(_eocb) ;
adcurrent=_adrh;
_acc=adcurrent;
return adcurrent;
}
char get_currentvalue(unsigned char value)
{unsigned char u;
if(value>=0x58)
{u=0x57;}
else
{u=value;}
return currentvalue[u];
}
void disp_high(unsigned char c_high)
{
unsigned char high_show;
unsigned char ast;
unsigned char datashow;
high_show=currentshow[c_high];
ast=(high_show&0x0f);
_bp=0x01;
_mp1=0x52;
_iar1=ast;
_swap(&high_show);
ast=(high_show&0x0f);
_mp1=0x51;
_iar1=ast;
}
void disp_mid(unsigned char c_mid)
{unsigned char mid_show;
unsigned char ast;
unsigned char datashow;
mid_show=currentshow[c_mid];
ast=(mid_show&0x0f);
_bp=0x01;
_mp1=0x50;
_iar1=ast;
_swap(&mid_show);
ast=(mid_show&0x0f);
_mp1=0x4f;
_iar1=(ast|0x80);
}
void disp_zero(unsigned char c_mid)
{unsigned char mid_show;
unsigned char ast;
unsigned char datashow;
mid_show=currentshow[c_mid];
ast=(mid_show&0x0f);
_bp=0x01;
_mp1=0x4e;
_iar1=ast;
_swap(&mid_show);
ast=(mid_show&0x0f);
_mp1=0x4d;
ast=(ast|0x08);
_acc=ast;
_iar1=ast;
_acc=_iar1;
}
void disp_high_null()
{
_bp=0x01;
_mp1=0x52;
_iar1=0x00;
_mp1=0x51;
_iar1=0x00;
_acc=_iar1;
}
void disp_current_value(unsigned int c_value)
{ unsigned int high;
unsigned int mid;
mid=(c_value&0x0f);
_acc=mid;
_swap(&c_value);
_acc=c_value;
high=(c_value&0x0f);
if(high==0x03)
{disp_high(0x03);}
else
{if(high==0x02)
{disp_high(0x02);}
else
{if(high==0x01)
{disp_high(0x01);}
else
{disp_high_null();}
}
}
disp_mid(mid);
disp_zero(0x00);
}
void clr_screen()
{unsigned int i;
_bp=0x01;
_mp1=0x49;
for(i=0;i<10;i++)
{
#asm
mov a,0h
mov [02],a
#endasm
//_iar1=0x00;
_mp1=_mp1+0x1;
}
}
void main() //show the input current
{
unsigned int curvalue;
unsigned int i;
unsigned char *solarcurrent;
unsigned char datadeal;
unsigned char pointocurrent;
unsigned char t=0x020;
p=(unsigned char *)0x028;
io_init();
int_init();
timer_base_interrupt();
while(1)
{
pointocurrent=ad_converter();
curvalue=get_currentvalue(pointocurrent);
disp_current_value(curvalue);
_delay(7000);
clr_screen();
_delay(100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -