单片机广告灯程序(89C51)

单片机广告灯程序(89C51),第1张

接电姿中路注意,二极管正迹老山极接电源VCC,是低电平驱动含虚

ORG00H

SJMPSTAR

STAR:ORG 30H

LOOP: MOV P1,#00H

LCALL DELAY

MOVP1,#AAH

LCALL DELAY

MOV P1,#55H

LCALL DELAY

MOV P1,#0F0H

LCALL DELAY

MOVP1,#0FH

LCALL DELAY

LJMPLOOP

DELAY:MOV R7,#250 延时0.5秒需要更长的话多加几个LCALL DELAY

D1: MOV R6,#250

D2:NOP

NOP

NOP

NOP

NOP

NOP

DJNZ R6,D2

DJNZ R7,D1

RET

END

#include<reg51.h>

#define uchar unsigned char

uchar ledt[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}

uchar ledi[]={0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7e)

uchar nt=0,ni=0

void timer0() interrupt 1

{

TH0=(65536-50000)/256

TL0=(65536-50000)%256

switch(nt)

{

case 0:

case 1:

case 2:

case 3:

case 4:

case 5:

case 6:

case 7:

P1=ledt[nt]break

case 8:

case 9:

case 10:

case 11:

case 12:

case 13:

case 14:

p1=ledt[14-nt]break

case 15:

P1=0x00break

case 16:

P1=0xffbreak

default:

nt=0break

}

nt++

}

void ext0() interrupt 0

{

switch(ni)

{

case 0:

case 1:

case 2:

case 3:

case 4:

case 5:

case 6:

case 7:

P1=ledt[ni]break

case 8:

case 9:

case 10:

case 11:

case 12:

case 13:

case 14:

P1=ledt[14-ni]break

case 15:

P1=0xffbreak

case 16:

P1=0x00break

default:

ni=0break

}

}

void delay(uchar a)

{

uchar i,j

for(i=0i<ai++)

for(j=0j<120j++)

}

main()

{

TMOD=0x01

TH0=(65536-50000)/256

TL0=(65536-50000)%256

ET0=1

EX0=1

IT0=0

EA=1

TR0=1

while(1)

{

while(P3_2)

{

TR0=0

delay(50)

ni++

}

TR0=1

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8187175.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存