Sherratian_Li 于 2015.07.11 15:47 提问

51单片机定时器中断问题

#include
#include
#define uchar unsigned char
#define uint unsigned int

sbit key=P3^7;
uchar display[8][8];
/*rank:Z,H,B,I,T,I,心,U*/
uchar code table_cha[8][8]={0x7E, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x7E,
0x66, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x66,
0x3E, 0x66, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x3E,
0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C,
0x7E, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C,
0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C};

void sinter()
{
IE=0x83; //允许INT0和T0中断
IP=0x01; //设置中断优先级
TCON=0x01; //设置INT0工作方式为边沿触发
TMOD=0x00;
TH0=0xc0;
TL0=0; //假设为方式0，初值为1100/0000/00000B 要求的定时值为1.024ms
TR0=1;

}
void delay5us(void) //误差 -0.026765046296us STC 1T 22.1184Mhz
{
unsigned char b;
for(b=7;b>0;b--);
//for(a=2;a>0;a--);
}

void delay(uint i)

{

``````     while (i--){
delay5us();}//12t的mcu 注释这个延时即可
``````

}

//将table_cha中第cha行元素赋给display第y列
void type(uchar cha,uchar y)

{

uchar xx;
for (xx=0;xx<8;xx++)
{
display[xx][y]=table_cha[cha][xx];
}
}

//使display中元素均为le
void clear(char le)

{
uchar i,j;
for (j=0;j<8;j++)
{
for (i=0;i<8;i++)
display[j][i]=le;
}
}

void flash()
{

``````     clear(0);
type(0,0);
delay(60000);
delay(60000);      //0.6s
type(1,0);
delay(60000);
delay(60000);
type(2,0);
delay(60000);
delay(60000);
type(3,0);
delay(60000);
delay(60000);
type(4,0);
delay(60000);
delay(60000);
type(5,0);
delay(60000);
delay(60000);
type(6,0);
delay(60000);
delay(60000);
type(7,0);
delay(60000);
delay(60000);
clear(0);
``````

}

void main()
{
while(1)
{

flash();
}

clear(0);
}

void print() interrupt 1
{
uchar i;
static uchar layer=0;
P1=0;
for (i=0;i<8;i++)
{
P2=1<<i; //依次扫描1-8片
delay(3);
P0=display[layer][i];
delay(3);
}
P1=1<<layer;

if (layer<7)
layer++;

``````     else
layer=0;
TH0=0xc0;
TL0=0;
``````

}

void pause () interrupt 0
{
while(!key){}
}

4个回答

devmiao      2015.07.11 22:42
Sherratian_Li 多谢啦，已经解决了，没有把初始化函数写进主函数。。。

devmiao      2015.07.11 22:42
CSDNXIAON   2015.07.16 15:23

51单片机中断问题
C51单片机 的定时器学习笔记
51单片机定时器计数器中断总结
----------------------同志你好，我是CSDN问答机器人小N，奉组织之命为你提供参考答案，编程尚未成功，同志仍需努力！

qq_16924151   2015.08.06 07:54