qbone
Member level 3
- Joined
- Jun 2, 2009
- Messages
- 58
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Lyngby, Denmark
- Activity points
- 1,778
Hey guys.
I am currently trying to learn assembly programming of PIC processors, and is following the tutorial on pcbheaven.com.
I have reached the point where I need to get an LED to flash, but it just wont
The tutorials are aimed for a PIC16F88, but I am converting it to fit my PIC as I go on, and I THINK I have done it right so far - but I guess its not all right since it doesnt work
I have searched high and low and found an answer on this forum where someone tells a guy to use the delay routine generator located at
I have tried that and implemented my code, but it still doesnt work.
Here are my code:
And before someone asks, this is the content of init_normal.inc :
I am programming in MPAB v8.85 and my programmer is a Olimex PIC-MCP-USB (Basicly a PICSTART+, atleast thats what they say )
- - - Updated - - -
This is my setup on the breadboard http://pcbheaven.com/picpages/images/ledflasher_1250600962.jpg (again - I am using PIC16F886, so I just did the same more or less.)
I am currently trying to learn assembly programming of PIC processors, and is following the tutorial on pcbheaven.com.
I have reached the point where I need to get an LED to flash, but it just wont
The tutorials are aimed for a PIC16F88, but I am converting it to fit my PIC as I go on, and I THINK I have done it right so far - but I guess its not all right since it doesnt work
I have searched high and low and found an answer on this forum where someone tells a guy to use the delay routine generator located at
I have tried that and implemented my code, but it still doesnt work.
Here are my code:
Code:
list F=inhx8m, P=16F886, R=hex, N=0
#include <P16F886.INC> ; PIC definitions
__config _config1,_INTOSCIO & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
__config _config2,_IESO_OFF & _FCMEN_OFF
Errorlevel -302 ; switches off Message [302]: Register in operand not in bank 0.
; RAM preserved -----------------------------------------------------------
cblock 0x20
WaitCounter,WaitCounter2
endc
; Program Memory ----------------------------------------------------------
org 0
goto Init
; Interrupt Service Routine -----------------------------------------------
org 4 ; ISR beginning
; Microcontroller initialization
Init
include init_normal.inc ;Include the PIC Initialization routine
; Main Program ------------------------------------------------------------
Start
bank1
movlw b'11111111' ;Set the port pin types of the RA
movwf TRISA ;All RA ports are inputs
movlw b'11111110' ;Set the port pin types of the RB
movwf TRISB ;All RB ports are input except RB0 that is output
bank0 ;Go to bank 0
MainLoop
bsf PORTB,0 ;Set RB0 output LOW
call Delay
bcf PORTB,0 ;Set RB0 output HIGH
call Delay
goto MainLoop ;And go back to the Main Loop
; Delay = 0.5 seconds
; Clock frequency = 4 MHz
; Actual delay = 0.5 seconds = 500000 cycles
; Error = 0 %
cblock
d1
d2
d3
endc
Delay
;499994 cycles
movlw 0x03
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;2 cycles
goto $+1
;4 cycles (including call)
return
Fins
end ; end of program
And before someone asks, this is the content of init_normal.inc :
Code:
bank1
movlw b'01100000'
movwf OSCCON
WaitForStableOscillator
btfss OSCCON,HTS
goto WaitForStableOscillator
movlw b'11111000' ; OPTION_REG setup
movwf option_reg
clrf pie1 ;
clrf pie2 ; No peripherial interrupt
clrf txsta ;Disable AUSART
;PSA must be to WDA (bsf OPTION_REG,psa)
bcf OPTION_REG,PS2
bcf OPTION_REG,PS1
bsf OPTION_REG,PS0
clrf adcon1 ;No analog to digital conversion
bank3
clrf ansel ; No analog to digital conversion
clrf anselh ; No analog to digital conversion
bank2
clrf CM1CON0 ;disable Comparator
clrf CM2CON0 ;disable Comparator
clrf CM2CON1 ;disable Comparator
bank0
;General
clrf rcsta ;Disable AUSART receive
clrf adcon0 ;No analog to digital conversion
I am programming in MPAB v8.85 and my programmer is a Olimex PIC-MCP-USB (Basicly a PICSTART+, atleast thats what they say )
- - - Updated - - -
This is my setup on the breadboard http://pcbheaven.com/picpages/images/ledflasher_1250600962.jpg (again - I am using PIC16F886, so I just did the same more or less.)