PDA

View Full Version : blink f675 Where I'm wrong?



Mike675
- 20th March 2005, 06: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

Melanie
- 20th March 2005, 10:47
In this thread...

http://www.picbasic.co.uk/forum/showthread.php?t=542

I gave an example of Blinking an LED (with detailed comments) in Assembler.

Melanie

PS. Since the thread being exclusively Assembler does not belong in the PICBasic categories, it's been moved here.

Mike675
- 17th April 2005, 19:43
Hi everybody,

Finally I found where the problem was hidden.
All my *.hex files are generated in a format which has at the end of the file a double 'retlw0'

----------------------
....
:0E01200083161E08A2000800851605120511A0 ;code in hex format
:02012E0000349B ;0034 - retlw 00h
:02013000003499 ;0034 - retlw 00h
:02400E00843FED
:00000001FF
----------------------
As you can see the last 4 lines are -my code
-2lines of retlw 00h :02012E0000349B
- config :02400E00843FED
- end of file :00000001FF
I checked the hex format at "http://www.cs.net/lucid/intel.htm"
I don't know yet all the details but after I deleted the 2 lines of retlw 00 and burn the new code resulted in the PIC, it just worked.

For those who build a code and have a successfully compiled *.hex file with no errors:
-when the code is burned into the PIC and doesn't work maybe this unscientific fix may work.

Mike