jamesr
Newbie level 6
- Joined
- Dec 4, 2013
- Messages
- 14
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 136
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 unsigned int i = 0; while(1){ for(i = 0; i < 256; i++){ PORTB = i; Delay_ms(500); } }
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _DEBUG_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving
;**********************************************************************
ORG 0x000 ; processor reset vector
nop ; nop required for icd
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
; isr code can go here or be located as a call subroutine elsewhere
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
; remaining code goes here
; *** main code goes here ***
BANKSEL TRISB
CLRF TRISB
BANKSEL PORTB
CLRF PORTB
test
movlw b'11111111'
movwf PORTB
goto test
END ; directive 'end of program'
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _DEBUG_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving
cblock 0x20 ; another way to specify user registers
d1,d2,d3 ; delay work files
endc
;************************************************* *********************
ORG 0x000 ; processor reset vector
nop ; nop required for icd
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
; isr code can go here or be located as a call subroutine elsewhere
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
; remaining code goes here
; *** main code goes here ***
BANKSEL TRISB
CLRF TRISB
BANKSEL PORTB
CLRF PORTB
test
movlw b'11111111'
movwf PORTB
call DELAY4s
comf PORTB
call DELAY4s
goto test
; SUBROUTINES
DELAY4s ; 4 SECOND DELAY
movlw 0x23
movwf d1
movlw 0xB9
movwf d2
movlw 0x09
movwf d3
Delay_0
decfsz d1, f
goto dly1
decfsz d2, f
dly1 goto dly2
decfsz d3, f
dly2 goto Delay_0
return
END ; directive 'end of program'
5) Background debug (if applicable to your target device). Leave this Disabled. If left Enabled this will use pins RB6 and RB7 and you will get some puzzling results if any I/P or O/P device are connected to these pins.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?