Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F818 assembler problem

Status
Not open for further replies.

Wendy Moss

New Member
Hello. This is my first venture into this forum. I usually "play" with RF, but recently I re awoke my interest in PIC programming. I designed a simple oscilloscope Time and Voltage calibrator. Digital is relatively easy. I then went onto trying to use the Analogue inputs. This is where it gets complicated. I first tried using the 16F690. However The code seemed to refuse just to light ONE led. So after many tries I bought a 16F818.
I faithfully copied the Config statements, and the Operating code, to light 8 leds depending upon the DC Voltage. However I understand that code printed in the data sheets.. may.. not be accurate....... for the chip config I used ( H'30C7').

See below where I think it is wrong.. but where ??

;**EQUATES SECTION*******

TMRO EQU 1
STATUS EQU 3
PORTA EQU 5
PORTB EQU 6
PORTC EQU 7
ZEROBIT EQU 2
ADCON0 EQU H'1F'
ADCON1 EQU H'9F'
ADRES EQU H'1E'
CARRY EQU H'00'
TRISA EQU H'85'
TRISB EQU H'86'
TRISC EQU H'87'
OPTION_R EQU H'81'
OSCCON EQU H'8F'
COUNT EQU H'20'


list p=16F690 ; list directive to define processor
org 0x04
goto start
#include <p16F690.inc> ; processor specific variable definitions

errorlevel -302 ; suppress message 302 from list file


;********MAIN_PROG CODE
CBLOCK 0x20 ; Start Data Block

CounterA ; for time delay
CounterB ; "
CounterC ; "

ENDC ; End of Data Block
;
; *******************************************************************************

; * The Interrupt vector is at 0x04. *
; *******************************************************************************

start
;***************CONFIGURATION SECTION***********
BSF STATUS,5 ;SWITCH TO BASNK 1
MOVLW B'00000100' ; PORT A INPUTS
MOVWF TRISA
MOVLW B'00000110' ; A1 & 2 Analog in
MOVWF ADCON1 ; A0,A3 DIGITAL I/P
; MOVLW B'00000000' ; PORT C OUT
; MOVWF TRISC
BCF STATUS,5 ; BACK TO BANK 0
MOVLW B'00000001' ; TURNS ON A/D CONVERTER
MOVWF ADCON0 ; SELECTS CHAN AN0
MOVLW B'00000000' ; PORTC OUT
MOVWF TRISC
CLRF PORTA
CLRF PORTC

Your assistance would be gratefully accepted
 
You don't seem to have anything at the reset vector? Should it be more like

org 0
goto start

org 4
goto interrupt

I've not really used PIC assembly for many years, I use C, so I can't help much with the rest of the code.

This is an example of a typical initialisation I used to use:

Code:
;
reset           goto    begin
                nop
                nop
                nop
intvec          goto    intrpt
  
begin           movlw   00              ;
                bcf     STATUS,RP0      ; Page 0
                movwf   PORTA           ; Ensure o/p's off
                movwf   PORTB           ;
;
                bsf     STATUS,RP0      ; Select page 1
;
; PAGE 1 Register setup ***
;
........
 
You might check my PIC tutorials?, but for a start you have a load of duplicated EQU at the beginning, these are mostly already included in the inc file. As already pointed out, you don't have anything at the reset vector - my code below deliberately writes over the interrupt vector, which as it's not been used is perfectly fine - it would be acomplete disaster otherwise though.

Here's the code from my first tutorial:

Code:
Tutorial 1.1

This simple program repeatedly switches all the output pins high and low.

          ;Tutorial 1.1 - Nigel Goodwin 2002
    LIST    p=16F628        ;tell assembler what chip we are using
    include "P16F628.inc"        ;include the defaults for the chip
    __config 0x3D18            ;sets the configuration settings
                    ;(oscillator type etc.)

    org    0x0000            ;org sets the origin, 0x0000 for the 16F628,
                    ;this is where the program starts running   
    movlw    0x07
    movwf    CMCON            ;turn comparators off (make it like a 16F84)

       bsf     STATUS,        RP0    ;select bank 1
       movlw     b'00000000'        ;set PortB all outputs
       movwf     TRISB
    movwf    TRISA            ;set PortA all outputs
    bcf    STATUS,        RP0    ;select bank 0

Loop   
    movlw    0xff
    movwf    PORTA            ;set all bits on
    movwf    PORTB
    nop                ;the nop's make up the time taken by the goto
    nop                ;giving a square wave output
    movlw    0x00
    movwf    PORTA
    movwf    PORTB            ;set all bits off
    goto    Loop            ;go back and do it again

    end

A later tutorial takes you through using the analogue inputs.
 
Your code doesn't appear to have a config instruction.

Mike.
Edit, also, in the chip you're using the ADC registers are in unusual locations,
adc.png

Edit2, they're in the same place as the 16F88 so code for that chip may work.
 
Last edited:
Your code doesn't appear to have a config instruction.

Mike.
Edit, also, in the chip you're using the ADC registers are in unusual locations,
View attachment 136921
Edit2, they're in the same place as the 16F88 so code for that chip may work.
As long as she uses the proper inc file (and doesn't duplicate it with incorrect entries) then it's makes no difference - that's why it's important to use inc files.
 
Hi folks.. Thanks for replying.. however... I realised.. after I had pressed the "send" button.. I had pasted the WRONG..code..that code was for a 16F690... I had two programmes open, and pasted the wrong one. However I will read your replies and thanks.
 
As long as she uses the proper inc file (and doesn't duplicate it with incorrect entries) then it's makes no difference - that's why it's important to use inc files.
And selects the correct bank when accessing them.

Mike.
 
I have had many discussions on all sorts of things with Wendy over the years and did point her to this forum as another place to find info and help, as she is a prolific experimenter, thankyou to all that have commented, I know she appreciates it.

On that note, I pointed her to the Gooligum tutorials in one of our discussions last night - they are now free and can be accessed here - https://github.com/gooligumelec/PIC-tutorials
 
Welcome Wendy. Good to know you have an excellent mentor in Terry.

Mike.
 
Hi members. Mike and Terry.. Thanks for the welcome and endorsement... As I have the data from the Gooligum web site..I am going back to retry a code conversion to 16F818... I will come back to you when I have tried it.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top