作者在 2011-03-04 23:04:28 发布以下内容
好久没发代码了,最近在学单片机,就写了一些简单的东西,高手见笑了!
#include<reg52.h>
#include<stdio.h>
unsigned int i=0;
typedef unsigned char unchar;
unchar Ledinit=0xE7;
unchar LedshiftL=0xDF;
unchar LedshiftR=0xFB;
unchar r=0x01;
unchar l=0x80;
unchar counter=0;
void Init_timer(void){
TMOD=0x22;
TH0=TL0=56;
TR0=1;
IT0=1;
}
void Init_uart(void){
SCON=0x50;
PCON=0x80;
TH1=TL1=0xFD;
TR1=1;
IT1=1;
TI=1;
}
void Init_INT(void){
EA=1;
ET0=1;
ES=1;
}
void main(void){
Init_timer();
Init_uart();
Init_INT();
P0=0xFF;
while(1);
}
void Int_timer(void) interrupt 1 using 0{
i++;
}
void Int_SCI(void) interrupt 4 using 1{
P0=Ledinit;
if(i==5000){
printf("世界你好!!!\n");
Ledinit=LedshiftL|Ledinit;
Ledinit=LedshiftL&LedshiftR;
LedshiftL=LedshiftL<<1;
LedshiftL=LedshiftL|r;
LedshiftR=LedshiftR>>1;
LedshiftR=LedshiftR|l;counter++;
if(counter==4){
Ledinit=0xE7;
LedshiftL=0xDF;
LedshiftR=0xFB;
counter=0;
}
i=0;
}
}
#include<stdio.h>
unsigned int i=0;
typedef unsigned char unchar;
unchar Ledinit=0xE7;
unchar LedshiftL=0xDF;
unchar LedshiftR=0xFB;
unchar r=0x01;
unchar l=0x80;
unchar counter=0;
void Init_timer(void){
TMOD=0x22;
TH0=TL0=56;
TR0=1;
IT0=1;
}
void Init_uart(void){
SCON=0x50;
PCON=0x80;
TH1=TL1=0xFD;
TR1=1;
IT1=1;
TI=1;
}
void Init_INT(void){
EA=1;
ET0=1;
ES=1;
}
void main(void){
Init_timer();
Init_uart();
Init_INT();
P0=0xFF;
while(1);
}
void Int_timer(void) interrupt 1 using 0{
i++;
}
void Int_SCI(void) interrupt 4 using 1{
P0=Ledinit;
if(i==5000){
printf("世界你好!!!\n");
Ledinit=LedshiftL|Ledinit;
Ledinit=LedshiftL&LedshiftR;
LedshiftL=LedshiftL<<1;
LedshiftL=LedshiftL|r;
LedshiftR=LedshiftR>>1;
LedshiftR=LedshiftR|l;counter++;
if(counter==4){
Ledinit=0xE7;
LedshiftL=0xDF;
LedshiftR=0xFB;
counter=0;
}
i=0;
}
}