Está en la página 1de 3

'****************************************************************************** '* Name : LED_Two_Ports.

mbas * '* Author : WIN HTET WIN * '* Notice : Copyright (c) 2012 * '* : All Rights Reserved * '* Date : 14/3/2013 * '* Version : 1.0 * '* Notes : PROCESSOR: PIC16F877A * '* : Crystal 4MHz * '* : Chasing LEDs in PORTB & PORTD in Step & Progressive Modes * '* : Compiler: mikroBasic Pro for PIC '****************************************************************************** program LED_Two_Ports ' Declarations section dim cnt as byte dim Cnt1 as byte dim Cnt2 as byte dim Cnt3 as byte main: ' Main program trisb = 0 trisd = 0 cnt = 1 'Right to Left in step Mode loop: portb = cnt portd = cnt delay_ms(500) if cnt = 128 then goto loopA else cnt = cnt<<1 end if goto loop loopA: portb = 0 portd = 0 delay_ms(500) goto loop1 cnt = 128 'Left to Right in Step Mode loop1: portb = cnt portd = cnt delay_ms(500) if cnt = 1 then goto loopB else cnt = cnt>>1 end if goto loop1 loopB: portb = 0 portd = 0 delay_ms(500) 'Right to Left in Progressive Mode

Cnt = 1 Cnt1 = 0 Cnt3 = 1 PORTB = Cnt portd = cnt delay_ms(500) FOR Cnt2 = 0 TO 6 Cnt1 = Cnt * 2 Cnt = Cnt1 Cnt3 = Cnt3 + Cnt PORTB = Cnt3 portd = cnt3 delay_ms(500) NEXT Cnt2 PORTB = 0 portd = 0 delay_ms(500) ' Left to Right in Progressive Mode Cnt = 128 Cnt1 = 0 Cnt3 = 128 PORTB = Cnt portd = cnt delay_ms(500) FOR Cnt2 = 0 TO 6 Cnt1 = Cnt / 2 Cnt = Cnt1 Cnt3 = Cnt3 + Cnt PORTB = Cnt3 portd = cnt3 delay_ms(500) NEXT Cnt2 PORTB = 0 portd = 0 delay_ms(500) ' PORTB ON & PORTD OFF PORTB = 255 PORTD = 0 DELAY_MS(500) PORTB = 0 PORTD = 0 DELAY_MS(500) ' PORTB OFF & PORTD ON PORTB = 0 PORTD = 255 DELAY_MS(500) PORTB = 0 PORTD = 0 DELAY_MS(500) ' PORTB OFF & PORTD ON PORTB = 0 PORTD = 255

DELAY_MS(500) PORTB = 0 PORTD = 0 DELAY_MS(500) ' PORTB ON & PORTD OFF PORTB = 255 PORTD = 0 DELAY_MS(500) PORTB = 0 PORTD = 0 DELAY_MS(500) ' PORTB ON & PORTD ON x THREE TIMES FOR Cnt2 = 0 TO 2 PORTB = 255 portd = 255 delay_ms(500) PORTB = 0 portd = 0 delay_ms(500) NEXT Cnt2 PORTB = 0 portd = 0 delay_ms(500) GOTO main end. end.

También podría gustarte