التجربة رقم 4 إضاءة متحركة لأعلى SCAN UP
الغرض :
تحريك إضاءة ليدات العامود الأول من أسفل إلى أعلى مع التكرار .
الفكرة :
وضع القيمة "0x01=0B00000001" بسجل المنفذ PORTB . هذا يؤدى إلى جعل البت الأدنى (RB0) فى الحالة المرتفعة HIGH وتكون النتيجة إضاءة الليد الأول (السفلى) بالعامود الأول .
بعد ذلك يتم إزاحة البت "1" جهة اليسار وهذا يؤدى إلى إضاءة الليد الثانى بالعامود (0B00000010) وهكذا .
لغة الأسمبلى :
كود:
;PIC16F84 and only F84 chip
;First column of LEDs scan from bottom to top at 2Hz.
Start ORG 0x00
BSF 03,5 ;Go to page1 for setting-up the ports
MOVLW 00h ;Put 00 into W
MOVWF 05h ;Make all RA lines output
MOVWF 06h ;Make all RB lines output
BCF 03,5 ;Go to Page0 for programming
MOVLW 02h ;Put 02 into W to
MOVWF 05h ; Reset the 4017
Scan BCF 03h,0 ;clear the carry flag
MOVLW 01h
MOVWF 06h
Scan1 CALL Delay
RLF 06h,1
GOTO Scan1
Delay MOVLW 03
MOVWF 1Ah
Delay1 DECFSZ 1Bh,1
GOTO Delay1
DECFSZ 1Ch,1
GOTO Delay1
DECFSZ 1Ah,1
GOTO Delay1
RETURN
END
لغة السى مع المترجم ميكروسى برو والميكروكونترولر PIC16F628A :
كود:
//PIC16F628A
//First column of LEDs scan from bottom to top at 2Hz.
char count;
void main (){ //Start
TRISA=0; // Make all RA lines output
TRISB=0; //Make all RB lines output
PORTA=0x02; // Reset the 4017
while(1){ //Endless loop
PORTB=0x01; // turn on first LED
for(count=0;count<6;count++){
Delay_ms(250); // Call Delay 250 ms
PORTB=PORTB<<1; // turn off first LED
Delay_ms(250); // Call Delay250 ms
}
}
}