It took a little while to get the time together for a proper reply... geeze... I'd forgotten what a pain it is to program in Assembler and remember all the little housekeeping chores that you never need to do in PICBasic...
Anyhow... here's the PICBasic code to flash your LED... I've inclued it as reference to show how easy life is...
Code:
'
' PIC Defines
' -----------
@ DEVICE pic16F870, XT_OSC
' System Clock Options
@ DEVICE pic16F870, WDT_ON
' Watchdog Timer
@ DEVICE pic16F870, PWRT_ON
' Power-On Timer
@ DEVICE pic16F870, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F870, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F870, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic16F870, PROTECT_OFF
' Program Code Protection
@ DEVICE pic16F870, WRT_OFF
' Flash Memory Word Enable
@ DEVICE pic16F870, DEBUG_OFF
' Debug
'
' Hardware Defines
' ----------------
LED var PortB.0
'
' Initialse Hardware
' ------------------
PORTB=0
TRISB=0
'
' Main Program Loop
' -----------------
Loop:
Low LED
Pause 500
High LED
Pause 500
Goto Loop
end
Now here's the Assembler... you should be able to simply cut & paste and Assemble with MPASM directly.... Note: This is NOT an exact and direct equivallent to the PICBasic code... for one thing the Delay Loop is fixed at 500mS (wild approximation at best for a very simple cascaded delay routine), and for another the delay code is only good for 4MHz.
Code:
; Blinky.ASM
; ==========
; A dinky program to Blink LED on RB0
; Includes Header for 16F870
; (c) Melanie 2-Sept-2004
; download the PICMicro Mid-Range Refernce Manual
; for full command details
;
; PIC Defines
; -----------
list P=PIC16F870 ; Tells MPASM the target processor
include "p16f870.inc"
; without this statement you'd need to define the
; addresses of EVERY register you're going to use
; BEFORE you use it
__config _XT_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CPD_ON & _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF
; Tells MPASM our Configuration Fuse Definitions
; go look at the file P16F870.INC in your MPASM Directory
;
; Hardware Defines (what's where in the real world)
; -------------------------------------------------
#DEFINE LED PORTB,0 ; Neat way of defining what's on a pin
; You can only use references like PORTB when you have
; previously defined them... that's been neatly done
; for you in the above include file
;
; Software Defines (what's where in our virtual world)
; ----------------------------------------------------
COUNTERA equ 20h ; 8-bit Byte (RAM) see PIC16F870 datasheet Figure 2-2
COUNTERB equ 21h
COUNTERC equ 22h
;
; Program always Starts executing at the Reset Vector
; ---------------------------------------------------
org 000h ; PIC Starts execution here
goto Start
;
; Actual Application Code Starts here (beyond the Vector Area)
; ------------------------------------------------------------
org 005h ; See PIC16F870 Datasheet Figure 2-1
;
; Subroutines get dumped first
; ============================
;
; Subroutine Kills 500mS (assumes 4MHz Clock)
; -------------------------------------------
; 500mS=(4uS Loop * 250 * 100 * 5)
;
Delay
movlw 0FAh ; Load COUNTERA with decimal 250
movwf COUNTERA
movlw 064h ; Load COUNTERB with decimal 100
movwf COUNTERB
movlw 005h ; Load COUNTERC with decimal 5
movwf COUNTERC
DelayA
CLRWDT ; DelayA gives 4uS Loop and keeps Watchdog chained up
decfsz COUNTERA,1 ; with COUNTERA preloaded with 0FAh (Decimal 250)
Goto DelayA ; this Loop Kills 1ms (4uS * 250)
decfsz COUNTERB,1 ; with COUNTERB preloaded with 064h (Decimal 100)
Goto DelayA ; this loop kills 100ms (1ms * 100)
decfsz COUNTERC,1 ; with COUNTERC preloaded with 005h (Decimal 5)
Goto DelayA ; this loop kills 500mS (100mS * 5)
return
;
; Actual Program Begins Here
; ==========================
Start
;
; Initialise Registers
; --------------------
clrf PORTB ; Zero PORTB
bsf STATUS,RP0 ; Switch to Bank 1
clrf TRISB ; Set PORTB all Outputs
; MPASM will report a reminder Warning here, because TRISB is in Bank1
; but we've handled it by Bank-Switching so we can ignore it.
; You just HAD to pick a PIC (16F870) with an ERROR in the datasheet...
; The RP Table in section 2.2 is CORRECT, however the RP bits (bits 6:5)
; in the STATUS Register description on DS30569B-Page-16 are SCREWED!
bcf STATUS,RP0 ; Return to Bank 0
;
; Main Program Loop
; -----------------
Loop
bcf LED ; Drive LED Low
call Delay ; Timeout
bsf LED ; Drive LED High
call Delay ; Timeout
Goto Loop ; do it till Doomsday
end
Yes, I did check it all worked before posting the code here... Enjoy...
Melanie
Bookmarks