Electronics > Microcontrollers

Having trouble writing blinky program with PIC assembly language

(1/4) > >>

DaveHardy:
Does anybody know what I'm doing wrong?  I'm having trouble with some of the instructions.  The 16F1827 has a few extra commands in the data sheet for initializing the port A register via banksel that I don't quite get.   From the datasheet:

http://ww1.microchip.com/downloads/en/DeviceDoc/41391D.pdf

; This code example illustrates
; initializing the PORTA register. The
; other ports are initialized in the same
; manner.
BANKSEL PORTA ;
CLRF PORTA ;Init PORTA
BANKSEL LATA ;Data Latch
CLRF LATA ;
BANKSEL ANSELA ;
CLRF ANSELA ;digital I/O
BANKSEL TRISA ;
MOVLW B'00111000' ;Set RA<5:3> as inputs
MOVWF TRISA ;and set RA<2:


I'm sure that it's something stupid.  I know almost nothing about these things.   This is my first program and I copied some of the instructions from a textbook.
Here's my program and what I get when I try to Build it:

;************************************
; written by: Me
; date: 2/17/2012
; version: 1.0
; file saved as: Test1
; for PIC16F1827 E/P
; clock frequency: Internal
;************************************

list  p=16f1827      ; list directive to define processor
#include <P16F1827.INC> ; processor specific variable definitions

__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF


;============
; Declarations:
porta   equ   05
      org 7FFFh
      goto Start
      org 0
;============
; Subroutines:
Init    clrf porta ; resets Port A
      movlw b’00000000’ ; RA0: LED, RA1-7: not connected
      tris porta
      retlw 0
;============
; Program Start:
Start    call Init ; sets up inputs and outputs
Main    bsf  porta, 0 ; turns on LED
      goto Main ; loops back to Main
END


----------------------------------------------------------------------
Debug build of project `C:\Users\Alexander Robotnick\Desktop\Test1.mcp' started.
Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
Preprocessor symbol `__DEBUG' is defined.
Fri Feb 17 15:12:19 2012
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F1827 "Test1.asm" /l"Test1.lst" /e"Test1.err" /o"Test1.o" /d__DEBUG=1
Warning[205] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 11 : Found directive in column 1. (list)
Warning[205] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 14 : Found directive in column 1. (__CONFIG)
Warning[205] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 15 : Found directive in column 1. (__CONFIG)
Error[113]   C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 27 : Symbol not previously defined (b’00000000’)
Warning[224] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 28 : Use of this instruction is not recommended.
Warning[205] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 35 : Found directive in column 1. (END)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Users\Alexander Robotnick\Desktop\Test1.mcp' failed.
Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
Preprocessor symbol `__DEBUG' is defined.
Fri Feb 17 15:12:20 2012
----------------------------------------------------------------------
BUILD FAILED

-Dave


8086:
Change the b'00000000' to 0x00 or simply 00

If it works, then I suspect there is a problem with your apostrophe character. It certainly looks different to mine.

EDIT: Also, your program as it is won't blink the LED, it will just turn it on.

EDIT 2: You also seem to have a weird execution order and some needless repeated instructions for the org/init parts of the program.

cybergibbons:
It hurts my head that someone with the nick 8086 is instructing someone else in PIC ASM.

DaveHardy:

--- Quote from: 8086 on February 17, 2012, 10:37:45 pm ---Change the b'00000000' to 0x00 or simply 00

If it works, then I suspect there is a problem with your apostrophe character. It certainly looks different to mine.

EDIT: Also, your program as it is won't blink the LED, it will just turn it on.

EDIT 2: You also seem to have a weird execution order and some needless repeated instructions for the org/init parts of the program.

--- End quote ---

Man, that stupid apostrophe!!!  Great Eyes!! I know it won't blink yet, that is the next step:)

I don't understand what is weird about my execution order.  What instructions are needless?   I'm trying to do the best I can and follow the program the way that it is explained in the book. 

From The Pic Microcontroller - Your Personal Introductory Course, 3rd Ed by John Morton:

"We want the PIC microcontroller to begin at the place in the program which we have
labelled start, so we make sure the instruction at 1FFh is goto start. In the
template, org is used to place instruction goto start at 1FFh, making it the first
to be executed. However, subsequent instructions must start counting from 0, so
the following command is org 0. Writing the program memory address by the
instructions shows how it works:
         org 1FF
01FF goto start
         org 0
;===========
; Subroutines:
0000 Init clrf porta ;
0001 clrf portb ;
etc.
The first instruction to be executed (goto start) makes the chip goto ( jump)
to the part of the program labelled start, and thus the PIC microcontroller will
begin running the program from where you have written start."

The whole org routine does seem stupid to me too but I don't really know what to do about it.   

Here's my latest Build Failed:

Debug build of project `C:\Users\Alexander Robotnick\Desktop\Test1.mcp' started.
Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
Preprocessor symbol `__DEBUG' is defined.
Fri Feb 17 17:07:41 2012
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F1827 "Test1.asm" /l"Test1.lst" /e"Test1.err" /o"Test1.o" /d__DEBUG=1
Warning[205] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 11 : Found directive in column 1. (list)
Warning[205] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 14 : Found directive in column 1. (__CONFIG)
Warning[205] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 15 : Found directive in column 1. (__CONFIG)
Warning[224] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 28 : Use of this instruction is not recommended.
Warning[205] C:\USERS\ALEXANDER ROBOTNICK\DESKTOP\TEST1.ASM 35 : Found directive in column 1. (END)
Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\mplink.exe" /p16F1827 "Test1.o" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"Test1.cof" /M"Test1.map" /W
MPLINK 4.41, Linker
Device Database Version 1.5
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section '.org_0' can not fit the absolute section. Section '.org_0' start=0x00007fff, length=0x00000002
Errors    : 1

Link step failed.
----------------------------------------------------------------------
Debug build of project `C:\Users\Alexander Robotnick\Desktop\Test1.mcp' failed.
Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
Preprocessor symbol `__DEBUG' is defined.
Fri Feb 17 17:07:42 2012
----------------------------------------------------------------------
BUILD FAILED

8086:

--- Quote from: DaveHardy on February 17, 2012, 11:46:07 pm ---Man, that stupid apostrophe!!!  Great Eyes!! I know it won't blink yet, that is the next step:)

I don't understand what is weird about my execution order.  What instructions are needless?   I'm trying to do the best I can and follow the program the way that it is explained in the book. 

--- End quote ---

The problem is the whole business with the reset vector. For the PIC16F1827, the reset vector is 0000h, and the program memory space ends at 0FFFh, so when you try and assemble this:


--- Code: ---      org 7FFFh
      goto Start
      org 0
--- End code ---

You are asking for it to put the first instruction in a non existent location.

The code should read:


--- Code: ---      org 0x00
      goto Start
--- End code ---

And the rest of the code will follow in sequential memory locations.

What I was saying about the unnecessary instructions is actually not an issue, I didn't see your retlw instruction at the end of init the first time around. Going to start to then call init and then go to main is quite a roundabout way of doing it, though.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version