#include "f2407regs.h" #include <stdlib.h> #include <stdio.h> #include <ctype.h> #include <math.h> #include <string.h>
void inline disable(void) /*可屏蔽中断禁止*/ { asm(" setc INTM "); }
void inline enable(void) /*未屏蔽中断使能*/ { asm(" clrc INTM "); }
void initial(void) { asm (" clrc CNF"); /*b0被设置为数据存储空间*/ asm (" clrc OVM "); /*累加器中结果正常溢出*/ asm (" setc SXM "); /*符号扩展有效*/ *SCSR1 = *SCSR1|0x0001; /* EVA模块使能*/ *WDCR=0x00e8; *IMR = *IMR|0X0002; /*中断级INT2被使能,其它屏蔽*/ *IFR = 0XFFFF; /*清除中断标志*/ }
void timerlint(void) { *EVAIFRA = *EVAIFRA|0X0080; /*上溢中断标志复位*/ *EVAIMRA = *EVAIMRA|0x0080; /*上溢中断使能*/ *T1CON = 0X9005; /*t1连续增计数,定时器禁止,内部时钟,不倍频,等于周期寄存器时重装载*/ *T1CNT=0X00; *T1CMPR = 0X00FF; *T1PR = 0XFFFF; }
void bright(void) { *MCRC = *MCRC & 0xbfff; *PFDATDIR = *PFDATDIR | 0x4040; }
void black(void) { *MCRC = *MCRC & 0xbfff; /*暗的小灯*/ *PFDATDIR = *PFDATDIR | 0x4000; *PFDATDIR = *PFDATDIR & 0xffbf; }
void interrupt T1PINT() /*上溢中断服务程序*/ { int flag,i; *T1CNT = 0X00; flag = *EVAIFRA & 0X0400; /*检测上溢中断标志是否为一*/ black(); if (flag != 0x0400) /*不为一*/ { enable(); /*开总中断*/ return; } *EVAIFRA = 0X0400; /*复位上溢中断标志*/ i++; bright(); if(i==7) {i=0; bright(); } return; }
void interrupt nothing() { enable(); return; }
void main(void) { disable(); initial(); timerlint(); enable(); *T1CON = *T1CON | 0X0040; while(1) { ; } }
|