Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- list p=16F684 ; list directive to define processor
- #include <p16f684.inc> ; processor specific variable definitions
- __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
- radix dec ; default radix is decimal
- errorlevel -302 ; suppress warnings when accessing SFRs in bank 1
- ;****************************** Assignment Statements ****************************
- ; Set up two counters to count down a delay
- COUNT1 EQU 20h ; Available GPR at address 20h used for storing COUNT1
- COUNT2 EQU 21h ; Available GPR at address 21h used for storing COUNT2
- ;******************************* #define Preprocessor statements *****************
- ; Define the 'direction' TRISA configuration for all leds
- #define TRISA_D01 B'00001111' ; D1 connected between RA4 and RA5
- #define TRISA_D23 B'00101011' ; D2 connected between RA4 and RA5
- #define TRISA_D45 B'00011011' ; D4 connected between RA4 and RA5
- #define TRISA_D67 B'00111001' ; D7 connected between RA4 and RA5
- ;6427717
- ; Define the 'data output' PORTA setting for switching ON the LEDs D2 to D3
- #define LED_D0_ON B'00010000' ; Sending HIGH to D0
- #define LED_D1_ON B'00100000' ; Sending HIGH to D1
- #define LED_D2_ON B'00010000' ; Sending HIGH to D2
- #define LED_D3_ON B'00000100' ; Sending HIGH to D3
- #define LED_D4_ON B'00100000' ; Sending HIGH to D4
- #define LED_D5_ON B'00000100' ; Sending HIGH to D5
- #define LED_D6_ON B'00000100' ; Sending HIGH to D6
- #define LED_D7_ON B'00000010' ; Sending HIGH to D7
- ;****************************** Start of Program- Initial configuration
- org 0x000 ; Processor reset vector
- bcf STATUS,RP0 ; Bank 0 selected
- movlw 07h ; Set RA<2:0> to digital and
- movwf CMCON0 ; Comparators turned OFF
- bsf STATUS,RP0 ; Bank 1 selected
- clrf ANSEL ; Digital I/O selected
- movlw B'00111111' ; Move in W - 0x3F - Set all I/O pins as digital inputs
- movwf TRISA ; Configure I/O ports
- clrf INTCON ; Disable all interrupts, clear all flags
- bcf STATUS,RP0 ; Bank 0 selected
- clrf PORTA ; Clear all outputs
- movlw 0xff ; First load a value of say, F0h in the W register
- movwf COUNT2 ; Now move it to COUNT2 register
- START
- bsf STATUS,RP0 ; Bank 1 selected
- movlw TRISA_D67 ; Configure LEDs D6 and D7 in TRISA
- movwf TRISA
- bcf STATUS, RP0 ; Bank 0 selected
- movlw LED_D6_ON ; Write '1' for D6 into Working Register
- movwf PORTA ; Send '1' through PORTA to light up LED D6
- call DELAY
- clrf PORTA ; Clear PORTA
- call DELAY
- bsf STATUS, RP0 ; Bank 1 selected
- movlw TRISA_D45 ; Configure LEDs D4 and D5 in TRISA
- movwf TRISA
- bcf STATUS, RP0 ; Bank 0 selected
- movlw LED_D4_ON ; Write '1' for D4 into Working Register
- movwf PORTA ; Send '1' through PORTA to light up LED D4
- call DELAY
- clrf PORTA ; Clear PORTA
- call DELAY
- bsf STATUS, RP0 ; Bank 1 selected
- movlw TRISA_D23 ; Configure LEDs D2 and D3 in TRISA
- movwf TRISA
- bcf STATUS, RP0 ; Bank 0 selected
- movlw LED_D2_ON ; Write '1' for D2 into Working Register
- movwf PORTA ; Send '1' through PORTA to light up LED D2
- call DELAY
- clrf PORTA ; Clear PORTA
- call DELAY
- bsf STATUS, RP0 ; Bank 1 selected
- movlw TRISA_D67 ; Configure LEDs D6 and D7 in TRISA
- movwf TRISA
- bcf STATUS, RP0 ; Bank 0 selected
- movlw LED_D7_ON ; Write '1' for D7 into Working Register
- movwf PORTA ; Send '1' through PORTA to light up LED D7
- call DELAY
- clrf PORTA ; Clear PORTA
- call DELAY
- movlw LED_D7_ON ; Write '1' for D7 into Working Register
- movwf PORTA ; Send '1' through PORTA to light up LED D7
- call DELAY
- clrf PORTA ; Clear PORTA
- call DELAY
- bsf STATUS, RP0 ; Bank 1 selected
- movlw TRISA_D01 ; Configure LEDs D0 and D1 in TRISA
- movwf TRISA
- bcf STATUS, RP0 ; Bank 0 selected
- movlw LED_D1_ON ; Write '1' for D1 into Working Register
- movwf PORTA ; Send '1' through PORTA to light up LED D1
- call DELAY
- clrf PORTA ; Clear PORTA
- call DELAY
- bsf STATUS, RP0 ; Bank 1 selected
- movlw TRISA_D67 ; Configure LEDs D6 and D7 in TRISA
- movwf TRISA
- bcf STATUS, RP0 ; Bank 0 selected
- movlw LED_D7_ON ; Write '1' for D7 into Working Register
- movwf PORTA ; Send '1' through PORTA to light up LED D7
- call DELAY
- clrf PORTA ; Clear PORTA
- call DELAY
- goto START ; loop again - Loop forever - blink continuously
- DELAY
- LOOP1
- decfsz COUNT1,1 ; Decrement COUNT1 and skip next instruction if zero
- goto LOOP1 ; else loop back to LOOP1
- decfsz COUNT2,1 ; Decrement COUNT2 and skip next instruction if zero
- goto LOOP1 ; else loop back to LOOP1
- movlw 0xff ; Reload the second counter for the next iteration
- movwf COUNT2
- return
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement