LED灯
#ifndef __LED_H__
#define __LED_H__
void Led_Disp(unsigned char ucLed);
#endif
------------------------------------------
#include "led.h"
void Led_Disp(unsigned char ucLed)
{
P0=~ucLed;
P2 = (P2 & 0x1f) | 0x80;
P2 &= 0x1f;
}
-------------------------------------------
#include "led.h"
void main(void)
{
while(1)
{
Led_Proc();
}
}
void Led_Proc(void)
{
}
定时器2
#ifndef __TIMER_H__
#define __TIMER_H__
#include <stc15f2s60k2.h>
void Timer2Init(void);
#endif
----------------------------------
void Timer2Init(void)
{
AUXR &= 0xFB;
T2L = 0x18;
T2H = 0xFC;
AUXR |= 0x10;
IE2 |= 0x04;
EA = 1;
}
-----------------------------------
#include "timer.h"
unsigned char ucLed;
void main(void)
{
Timer2Init(void);
}
void t2int() interrupt 12
{
Led_Disp(ucLed);
}