//--------------------------------------------------------51部份代码----------------------------------------------------------------//
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit SPK = P3^7;
uchar FRQ = 0x00;
void Delayms(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
void main()
{
P2 = 0x00;
TMOD = 0x11;
TH0 = 0x00;
TL0 = 0xff;
IT0 = 1;
TR0 = 0;
TR1 = 0;
while(1)
{
FRQ++;
Delayms(1);
}
}
void EX0_INT() interrupt 0
{
TR0 = !TR0;
TR1 = !TR1;
}
void T0_INT() interrupt 1
{
TH0 = 0xfe;
TL0 = FRQ;
SPK = ~SPK;
}
void T1_INT() interrupt 3
{
TH0 = -4200/256;
TL0 = -4200%256;
P2 = _crol_(P2,1);
}
//--------------------------------------------------------AVR部份代码----------------------------------------------------------------//
#include<iom16v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar key = 0;
uchar led_huayang = 0xe0;
void delay_1ms(unsigned char z)
{
unsigned int i,j;
for(i=0;i<z;i++)
for(j=0;j<200;j++);
}
void main()
{
DDRC = 0xff;
DDRD =~ (1<<2);
PORTD = (1<<2);
GICR = 0X40;
SREG=0x80 ;
while(1)
{
chushizhi++;
delay_1ms(1);
}
}
#pragma interrupt_handler Timer0:iv_TIMER0_OVF
void Timer0()
{
TCNT0 = 183 ;
if( led_huayang & 0x80) led_huayang =( led_huayang<< 1 )| 0x01;
else led_huayang<<= 1;
PORTC = led_huayang;
}
#pragma interrupt_handler Timer1:iv_TIMER1_OVF
void Timer1()
{
TCNT1 = 0xfe00 + chushizhi;
SPK();
}
#pragma interrupt_handler int0_INT:2
void int0_INT(void)
{
key =! key;
if(key)
{
TIMSK |= 0X05;
led_huayang = 0xe0;
}
else
{
TIMSK = 0X00;
PORTC = 0X00;
PORTD &=~ (1<<7);
}
}
完全代码附件中
avr_bj_led.zip
(10.69 KB, 下载次数: 5)
51_bj_led.zip
(16.8 KB, 下载次数: 4)
|