/****开机自检函数****/
void Turn_on_test() {
uint i;
uint temp=0x0001; for(i=0;i<16;i++) { display(1,temp); //高电平点亮 delay_ms(1000); //间隔1s temp<<=1; } }
/****同心圆****/ void draw_circle() {
uint i; uint temp; temp=0x8000;
for(i=0;i<16;i++) //从小到大 { display(1,temp);
delay_ms(300); //间隔0.3s temp>>=1; }
temp=0x0001;
for(i=0;i<16;i++) //从大到小 { display(1,temp);
delay_ms(300); //间隔0.3s temp<<=1; } }
/****TI杯程序****/
void draw_TI_cup(uchar const *p) {
uint i; uint temp;
p=&sort_buff2[0];
for(i=0;i<32;i++) //32列 {
temp=*p++; //将一竖的两个字节合成一个字
16
temp<<=8; temp|=*p++; display(0,temp);
delay_320us(1); //间隔320us } }
/*****秒针程序****/ void draw_second_hand() {
uint temp1,temp2; temp1=0xfffc; temp2=0x0000;
delay_320us(2*(60-ts)); //延时,等待指向相应的位置 display(1,temp1|0x0001);
delay_320us(1); //在该亮的位置显示320us display(1,temp2|0x0001); }
/****主函数****/ void main(void) {
mcu_init(); TIMER_init(); P1_port_init();
Re_sort(); //从新排序 Turn_on_test(); //开机自检 _EINT(); //开总中断 while(1) {
}; }
#pragma vector=PORT1_VECTOR __interrupt void P1_port(void) {
if(P1IFG&BIT5) //按键切换模式 {
delay_ms(30);
if(P1IFG&BIT5)
17
{
P1IFG &=~(BIT5); count++;
if(count>=5) count=1; while(!(P1IN&BIT5)); } }
if(P1IFG&BIT1) {
P1IFG &=~(BIT1); if(count==1) {
P1IE&=~BIT1; //关中断 draw_circle();
P1IE|=BIT1; //同心圆显示完后开中断 }
else if(count==2) //每次霍尔中断就显示一次TI杯 {
P2OUT|=L_OE;
draw_TI_cup(sort_buff2); P2OUT|=L_OE; }
else if(count==3) {
TACTL|=MC_1; //开始定时 draw_second_hand(); }
else if(count==4) {
Clock_buff[0]=ts+0x30; Clock_buff[1]=ts/10+0x30; Clock_buff[3]=tm+0x30; Clock_buff[4]=tm/10+0x30; Clock_buff[6]=th+0x30; Clock_buff[7]=th/10+0x30; disp_ascii(Clock_buff); } } }
//Timer A0 interrupt service routine #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A0 (void) {
18
t50ms++; if(t50ms==20) {
t50ms=0; ts++; if(ts==60) {
ts=0; tm++; if(tm==60) {
tm=0;th++; if(th==24) th=0; } } } }
uchar const disp_buff[64]={
0x18,0x00,0x10,0x00,0x10,0x04,0x1F,0xFC, 0x10,0x04,0x10,0x00,0x18,0x00,0x00,0x00, 0x00,0x00,0x10,0x04,0x10,0x04,0x1F,0xFC, 0x10,0x04,0x10,0x04,0x00,0x00,0x00,0x00,
0x10,0x40,0x11,0x80,0x16,0x00,0xFF,0xFF, 0x12,0x00,0x51,0x20,0x40,0x40,0x40,0x80, 0x43,0x00,0x4F,0xFF,0x70,0x00,0x41,0x00, 0x40,0x80,0x40,0x60,0x40,0x30,0x00,0x00, };
uchar const num_buff[]={
0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,
0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00, /*\
0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x04,
0x1F,0xFC,0x08,0x04,0x08,0x04,0x00,0x00, /*\
//数据已经处理19
0x00,0x00,0x0E,0x0C,0x11,0x84,0x10,0x44,
0x10,0x24,0x10,0x14,0x0E,0x0C,0x00,0x00, /*\
0x00,0x00,0x0C,0x70,0x12,0x88,0x11,0x04,
0x11,0x04,0x10,0x04,0x0C,0x18,0x00,0x00, /*\
0x00,0x00,0x00,0x24,0x1F,0xFC,0x08,0x24,
0x04,0x24,0x03,0x20,0x00,0xE0,0x00,0x00, /*\
0x00,0x00,0x10,0x70,0x10,0x88,0x11,0x04,
0x11,0x04,0x10,0x84,0x1F,0x98,0x00,0x00, /*\
0x00,0x00,0x00,0x70,0x18,0x88,0x11,0x04,
0x11,0x04,0x08,0x88,0x07,0xF0,0x00,0x00, /*\
0x00,0x00,0x10,0x00,0x1C,0x00,0x13,0x00,
0x10,0xFC,0x10,0x00,0x1C,0x00,0x00,0x00, /*\
0x00,0x00,0x0E,0x38,0x11,0x44,0x10,0x84,
0x10,0x84,0x11,0x44,0x0E,0x38,0x00,0x00, /*\
0x00,0x00,0x07,0xF0,0x08,0x88,0x10,0x44,
0x10,0x44,0x08,0x8C,0x07,0x00,0x00,0x00, /*\
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,
0x03,0x0C,0x00,0x00,0x00,0x00,0x00,0x00, /*\};
20