start:movA,#01010101bmovP3,AacalldelaymovA,#10101010bmovP3,Aacalldelaysjmpstartdelay:movR0,#01h; 108 ms skok1:movR1,#100skok2:movR2,#250skok:DJNZR2,skokDJNZR1,skok2DJNZR0,skok1retend
org0;pseudoinstrukce umistujici program do pameti programu pocitace adresou 000hstart:movA,#P1movP3,Asjmpstart
Runing Light
org0;pseudoinstrukce umistujici program od 00hmovP3,#11111110B;0. bit na log "0"loop:movA,P3rlcA;posun obsah A přes C dolevamovP3,Aacalldelay;zavolá podprogram pro zpoždění 1ssjmploop;skočí zpět k rotaci P1delay:movR0,#01h;podprogram zpožděnískok1:movR1,#01hskok2:movR2,#01hskok:djnzR2,skokdjnzR1,skok2djnzR0,skok1retend
Runing Light C
#include<at89x51.h>#define LED P2_3voidmain(){inti;while(1){if(LED){LED=0;}else{LED=1;}{for(i=0;i<10000;i++);}}}
#include<at89x51.h>#include<delay.h>voidmain(){while(1){P1=0xff;_delay_ms(50);// 50 msP1=0x00;_delay_ms(50);// 50 ms}}/* file delay.h contains:unsigned int i,j;void _delay_ms(unsigned int msec) // crystal 10 059 kHz{ for(i=0;i<msec;i++) for(j=0;j<110;j++);}
7 segment
MOVDPTR,#TAB ;ulozi adresu cislic do DPTRnastav:MOVR5,#0;nastaveni prvni cislicezobraz:MOVA,R5;presun cislice z R5 do AMOVCA,@A+DPTR;vybere prislusnou hodnotu pro AMOVP3,A;presum hodnoty na portINCR5;zvysi cislo v R5 o 1 CJNER5,#10,zobrazSJMPnastavTAB:DB0C0h,0F9H,0A4H,0B0H,99H;0,1,2,3,4,DB92H,82H,0F8H,80H,90H;5,6,7,8,9,end
__sfr__at(0xB0)P3;#define DELAYTIME 15 //Defined delay time constant, originally 65000unsignedinttemp1;voiddelay(unsignedinttemp)//Delay process{while(--temp);}voidmain(){P3=255;//led is off HGFEDCBA = "1"while(1){P3=0Xc0;//0 HG = "1" OFFtemp1=DELAYTIME;delay(temp1);P3=0XF9;//1 BC = "0" = ONtemp1=DELAYTIME;delay(temp1);}}
7 segment - C (tab)
#include<at89x51.h>__codeunsignedcharout[16]={0xC0,0xF9,0xA4,0xB0,//0,1,2,30x99,0x92,0x82,0xF8,//4,5,6,70x80,0x90,0x08,0x03,//8.9.A.B0x46,0x21,0x06,0x0E};//C,D,E,Fvoidmain(void){__dataunsignedchari=0;while(1)// program loop{P3=out[i++];if(i==16)i=0;}}
Two 7-segment
MOVDPTR,#TAB tens:MOVP0,#00000010BMOVR5,#01Hunits:MOVR3,#00Hnext:MOVA,R3MOVCA,@A+DPTRMOVP2,AACALLdelayINCR3CJNER3,#10D,nextMOVA,R5MOVCA,@a+dptrMOVP0,AINCR5CJNER5,#11D,againSJMPtensagain:SJMPunitsdelay:MOVR2,#06Dtemp2:MOVR1,#255Dtemp1:MOVR0,#255DDJNZR0,$DJNZR1,temp1DJNZR2,temp2RETTAB:DB00000010B;0x02 0DDB10011111B;0x9F 1D DB00100100B;0x24 2D DB00001100B;0x1C 3D DB10011000B;0x98 4DDB01001000B;0x48 5DDB01000000B;0x40 6D DB00011110B;0x1E 7D DB00000000B;0x00 8D DB00001000B;0x0F 9D END
Counter
MOVTMOD,#00000001BMOVTH0,#00HMOVTL0,#00HSETBTR0MOVDPTR,#TAB ;ulozi adresu cislic do DPTRnastav:MOVR5,#0;nastaveni prvni cislicezobraz:MOVA,R5;presun cislice z R5 do AMOVCA,@A+DPTR;vybere prislusnou hodnotu pro AMOVP3,A;presum hodnoty na portINCR5;zvysi cislo v R5 o 1 acalltestCJNER5,#10,zobrazSJMPnastavtest:; ACALL ZPOZDJNBP1.0,$;bit P1.0=0 skok na sebe sama; ACALL ZPOZDJBP1.0,$;bit P1.0=1 skok na sebe samaretZPOZD:MOVR0,#05HSKOK:JNBTF0,$CLRTF0DJNZR0,SKOKRETTAB:DB0C0h,0F9H,0A4H,0B0H,99H;0,1,2,3,4,DB92H,82H,0F8H,80H,90H;5,6,7,8,9,end