Ⅰ 51單片機設計跑馬燈的程序用(c語言)編寫
|P1口接8個發光二極體共陽
#include <AT89X51.H>
unsigned char i;
unsigned char temp;
unsigned char a,b;
void delay(void)
{
unsigned char m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}
void main(void)
{
while(1)
{
temp=0xfe;
P1=temp;
delay();
for(i=1;i<8;i++)
{
a=temp<<i;
b=temp>>(8-i);
P1=a|b;
delay();
}
for(i=1;i<8;i++)
{
a=temp>>i;
b=temp<<(8-i);
P1=a|b;
delay();
}
}
}
(1)單片機匯編跑馬燈程序擴展閱讀:
Proteus 自從有了單片機也就有了開發系統,隨著單片機的發展開發系統也在不斷發展。 keil是一種先進的單片機集成開發系統。它代表著匯編語言單片機開發系統的最新發展,首創多項便利技術,將開發的編程/模擬/調試/寫入/加密等所有過程一氣呵成,中間不須任何編譯或匯編。
Ⅱ 用51單片機(匯編語言寫)寫一個跑馬燈程序知道的幫個忙寫寫。
急用!請教!!!
用匯編語言程序,程序功能:實現方向可控的跑馬燈
編程要求:用八個LED發光二極體實現跑馬燈(即:8個燈依次輪流發光,每次只亮一個燈),系統啟動後,跑馬燈右向流轉,按下K1鍵,則反向流轉,再按則再反向……。接線方法:流水燈接P0口,按鍵K1可自選P1~P3任一引腳。
Ⅲ 單片機89C51用匯編製作跑馬燈P1控制8個LED(D1~D8)燈實現流水燈的效果,高手速度來
很酷的流水燈
#include <reg51.h>
typedef unsigned char uchar;
#define Ton 40
#define LED P0
sbit leds=P1^4;
sbit LED0 = P0^0;
sbit LED1 = P0^1;
sbit LED2 = P0^2;
sbit LED3 = P0^3;
sbit LED4 = P0^4;
sbit LED5 = P0^5;
sbit LED6 = P0^6;
sbit LED7 = P0^7;
unsigned char Maikuan=0;
static unsigned char ledon[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchar Occupy_led; //占空比越大,燈越亮
bit light;
uchar m;
void Inittime()
{
TMOD = 0x02; //定時器0,工作方式2,自動重裝
TH0 = 256-Ton;
TL0 = 256-Ton;
ET0 = 1;
EA = 1;
TR0 = 1;
}
//定時器0中斷
void time0() interrupt 1 using 0
{
Maikuan++;
}
void main()
{
unsigned char i = 0,j = 0; //初始化i,j
leds=0;
Inittime();
while (1)
{
//第1,3,5,7個燈半亮,其餘的全亮。
for(i=254; i>0; i--)
{
while ( Maikuan!=20)
{
LED = 0x00;
}
while ( Maikuan!=200)
{
LED = 0x55;
}
Maikuan = 0;
}
//最難的:8個燈從第一個開始依次漸亮,直到最後一個。再從最後一個起漸暗,直到第一個。如此循環往復。
for(j = 0;j<=7;j++)
{
i = 0;
while(i!=255) // 由暗變亮
{
if( Maikuan == 0) // 點亮
{
LED = ledon[j];
}
if(Maikuan == i) // 熄滅
{
LED = 0xff;
}
if( Maikuan== 255)
{
i++;
}
}
}
for(j=7;j>=0;j--)
{
i = 0;
while(i!=255) // 由亮變暗
{
if(Maikuan == 0) // 熄滅
{
LED = 0xff;
}
if( Maikuan == i) // 點亮
{
LED = ledon[j];
}
if( Maikuan == 255)
{
i++;
}
}
}
//所有的燈逐漸從暗到全亮,再由全亮到暗。
for (m=254; m>0; m--)
{
while (Maikuan!=Occupy_led)
{
LED = 0x00;
}
while (Maikuan!=127)
{
LED = 0xff;
}
Maikuan = 0;
if (light)
{
Occupy_led++;
}
else
{
Occupy_led--;
}
if (Occupy_led==128)
{
Occupy_led = 127;
light = !light;
}
if (Occupy_led>128)
{
Occupy_led = 0;
light = !light;
}
}
}
}
Ⅳ 單片機跑馬燈程序 匯編語言編寫,很簡單
程序1:
ORG0000H
LJMPMAIN
ORG0030H
MAIN:
MOVSP,#5FH
LOOP:
MOVA,P2
MOVB,A
MOVP0,A
MOVP1,#0FFH
LOOP1:
LCALLDELAY
MOVC,P1.7
MOVA,P0
RLCA
MOVP0,A
MOVA,P1
RLCA
MOVP1,A
MOVA,P2
CJNEA,B,LOOP
SJMPLOOP1
DELAY:
MOVR2,#60
DELAY1:
MOVR3,#250
DJNZR3,$
DJNZR2,DELAY1
RET
END
程序2:
ORG0000H
LJMPMAIN
ORG0030H
MAIN:
MOVSP,#5FH
JNBP2.0,LOOP1;
JNBP2.1,LOOP2;
SJMPMAIN
LOOP1:
MOVP0,#0FEH
MOVP1,#0FFH
LOOP11:
MOVC,P1.7
MOVA,P0
RLCA
MOVP0,A
MOVA,P1
RLCA
MOVP1,A
JNBP2.1,LOOP2
SJMPLOOP11
LOOP2:
MOVP0,#0FCH
MOVP1,#0FFH
LOOP21:
MOVC,P1.7
MOVA,P0
RLCA
MOVP0,A
MOVA,P1
RLCA
MOVP1,A
JNBP2.0,LOOP1
SJMPLOOP21
DELAY:
MOVR2,#60
DELAY1:
MOVR3,#250
DJNZR3,$
DJNZR2,DELAY1
RET
END