Mike675
- 20th March 2005, 05:34
Hi everybody
I'm lost and I'm out of ideas how to make it work.
I start building a NiMH charger , but first of all I can't make blink a led.
I have tried some other blink.hex (downloaded) to check my hardware and the led blinks.
When I try to compile my *.asm file or those downloaded the resulting hex doesn't work - I supose my MPLAB settings are wrong, but where?
This is my code
list p=12f675 ; list directive to define processor
#include <p12f675.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;***** VARIABLE DEFINITIONS
w_temp EQU 0x20 ; variable used for context saving
status_temp EQU 0x21 ; variable used for context saving
temp1 EQU 0x22
temp2 EQU 0x23
temp3 EQU 0x24
led1 EQU 0x25
;************************************************* ******** ORG 0x000 ; processor reset vector
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
; isr code can go here or be located as a call subroutine elsewhere
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
; these first 4 instructions are not required if the internal oscillator is not used
main
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
; remaining code goes here
bcf STATUS,RP0 ; Sel Bank 0
movlw 0x07 ;
movwf CMCON ; Turn off comparator
bsf STATUS,RP0 ; Sel Bank 1
clrf ANSEL ;Digital I/O
movlw b'00001000' ; Specify GPIO port direction: all output, except GP3
movwf TRISIO ; Set GPIO ports as xxOOIOOO
bcf STATUS,RP0
led btfsc GPIO,0
goto offled
onled bsf GPIO,0 ;to power led drive pin low
goto temp
offled bcf GPIO,0
;Timer
temp movlw d'40' ;N=40
movwf temp1
tt3 movwf temp2 ;T~(N^3+N^2+N)*3
tt2 movwf temp3 ;T~0.2sec
tt1 decfsz temp3,1
goto tt1
decfsz temp2,1
goto tt2
decfsz temp1,1
goto tt3
goto led
END ; directive 'end of program'
led.hex generated (Ignore fuse 3F84 generate in my MPLAB and change it with 0184)
:020000040000FA
:020000000C28CA
:040002000034003492
:08000800A0000308A10021087B
:100010008300A00E200E0900FF2383169000831298
:100020000730990083169F01083085008312051858
:100030001B2805141C2805102830A200A300A400CA
:0E004000A40B2028A30B1F28A20B1E28172894
:02400E00843FED
:00000001FF
I'm lost and I'm out of ideas how to make it work.
I start building a NiMH charger , but first of all I can't make blink a led.
I have tried some other blink.hex (downloaded) to check my hardware and the led blinks.
When I try to compile my *.asm file or those downloaded the resulting hex doesn't work - I supose my MPLAB settings are wrong, but where?
This is my code
list p=12f675 ; list directive to define processor
#include <p12f675.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;***** VARIABLE DEFINITIONS
w_temp EQU 0x20 ; variable used for context saving
status_temp EQU 0x21 ; variable used for context saving
temp1 EQU 0x22
temp2 EQU 0x23
temp3 EQU 0x24
led1 EQU 0x25
;************************************************* ******** ORG 0x000 ; processor reset vector
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
; isr code can go here or be located as a call subroutine elsewhere
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
; these first 4 instructions are not required if the internal oscillator is not used
main
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
; remaining code goes here
bcf STATUS,RP0 ; Sel Bank 0
movlw 0x07 ;
movwf CMCON ; Turn off comparator
bsf STATUS,RP0 ; Sel Bank 1
clrf ANSEL ;Digital I/O
movlw b'00001000' ; Specify GPIO port direction: all output, except GP3
movwf TRISIO ; Set GPIO ports as xxOOIOOO
bcf STATUS,RP0
led btfsc GPIO,0
goto offled
onled bsf GPIO,0 ;to power led drive pin low
goto temp
offled bcf GPIO,0
;Timer
temp movlw d'40' ;N=40
movwf temp1
tt3 movwf temp2 ;T~(N^3+N^2+N)*3
tt2 movwf temp3 ;T~0.2sec
tt1 decfsz temp3,1
goto tt1
decfsz temp2,1
goto tt2
decfsz temp1,1
goto tt3
goto led
END ; directive 'end of program'
led.hex generated (Ignore fuse 3F84 generate in my MPLAB and change it with 0184)
:020000040000FA
:020000000C28CA
:040002000034003492
:08000800A0000308A10021087B
:100010008300A00E200E0900FF2383169000831298
:100020000730990083169F01083085008312051858
:100030001B2805141C2805102830A200A300A400CA
:0E004000A40B2028A30B1F28A20B1E28172894
:02400E00843FED
:00000001FF