小弟没学过PIC,这个程序是让A灯按a频率闪,B灯和C灯都按a的倍数的频率闪,前面定义的东西太多了看不明白。 #pragma , volatile什么的好高深...
请教谁能给个思路去理解这段程序。
unsigned char TCC,IOCE,RF,counter,counter_red,counter_blue;
void tcc_isr(void);
void __startup(void);
#pragma INTERRUPT_VECTOR tcc_isr
volatile union
{
unsigned int byte;
struct
{
unsigned int b0:1;
unsigned int b1:1;
unsigned int b2:1;
unsigned int b3:1;
unsigned int b4:1;
unsigned int b5:1;
unsigned int b6:1;
unsigned int b7:1;
}bit;
}Port6;
#pragma RAM_VAR TCC 0 0x01
#pragma RAM_VAR Port6 0 0x06
#pragma RAM_VAR RF 0 0x0f
#define IOCE 0x0e
#define IOCF 0x0f
#define TCIE 0x01
#define _IOW(adr,r) asm{MOV A,@r;IOW adr;}
#define _IOR(adr,r) asm{IOR adr;MOV r,A;}
#define _CONTW(r) asm{MOV A,@r;CONTW;}
#define _ENI asm{ENI;}
#define _WDTC asm{WDTC;}
void main(void)
{
_IOW(IOCF,TCIE);
_CONTW(0x05);
TCC = 81;
_ENI;
counter = 62;
counter_blue = 0;
counter_red = 0;
Port6.bit.b0 = 0;
Port6.bit.b4 = 0;
Port6.bit.b5 = 0;
while(1){}
}
void __startup(void)
{
asm
{
MOV A,@0x08
IOW 0x06
MOV A,@0xFF
IOW 0x0B
MOV A,@0x00
IOW 0x0C
MOV A,@0xC8
IOW 0x0D
}
}
void tcc_isr(void)
{
RF = 0;
TCC = 81;
counter--;
if(counter == 31)
{
Port6.bit.b0 = 1; //橙 {MOD}P60
counter_blue++;
counter_red++;
if(counter_blue == 4) //蓝 {MOD}P64
{
Port6.bit.b4 = 1;
}
if(counter_blue == 12)
{
Port6.bit.b4 = 0;
counter_blue = 0;
}
if(counter_red == 16) //红 {MOD}P65
{
Port6.bit.b5 = 1;
}
if(counter_red == 32)
{
Port6.bit.b5 = 0;
counter_red = 0;
}
}
else if(counter == 0)
{
Port6.bit.b0 = 0;
counter = 62;
}
asm RETI
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
是的话找到安装的文件夹,看看有没有pdf文件,一般有user guide,getting start,再看里边的#progma是什么意思。
no stupid mcus, just stupid mcu programmers.
一周热门 更多>