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.

newbie help

Status
Not open for further replies.

paulyt5966

New Member
hi all,im a total beginner to pic programing and im doing one of the tutorials based on the 12c508a and 16f84a the first project is to make a led turn on.

SetUp MOVLW 3E ;Make GP0 output
TRIS 06 ;Load TRISB file
Out0 MOVLW 01 ;Load W with 1
MOVWF 06 ;Make GP0 HIGH
GOTO Out0
END
i have simulated the above and it works so i changed 3E to 39h which i assume would make gp1 and gp2 high but when i run a simulation gp1 and gp2 doesnt seem to go high what have i missed?
i know this is probably such a simple thing for you all but we all had to start from scratch.
 
If you look at the binary values for the values you are using, you get:-

3E = 00111110 = GP0 is output - rest are input
39 = 00111001 = GP1 & GP2 are output

You then proceed to write 1 to GPIO which will set GP0 to 1. When you change your TRIS value to 39 then you should have changed the 1 to 6 (00000110).

HTH

Mike.
 
thanks pommie i understand that bit now.ive moved on to the next project now which is to flash an led on and off,ive loaded the hex into the chip and tried to simulate it using proteus simulator but it doesnt seem to flash,also i cant understand why gp3 is high as i thought this is input only for 12c508a can someone have a look at the asm below and tell me what the problem might be,i would like to get this working so then i could change the values ie time delays so i could then understand how they work,thanks

FlashLED1 BSF 03h,5 ;select page1
MOVLW 3e ;to make gp0 output
MOVWF 06
BCF 03h,5 ;select page0
Loop1 BSF 06,0 ;select bit0 high
CALL Delay1
BCF 06,0 ;make bit0 low
MOVLW 09 ;put 9 in w
MOVWF 0C ;oc is the loop file
AA1 CALL Delay1
DECFSZ 0C
GOTO AA1
GOTO Loop1


Delay1 MOVLW 82h ;130 loops
MOVWF 1A
DelX DECFSZ 1B ;256 decrements
GOTO DelX ;2uS instruction
DECFSZ 1A
GOTO DelX
RETLW 00
END
this program turns on led for 0.1s (delay1 routine) then off for 0.9s by calling delay1 nine times.
 
The above code should work fine on the 16F84 but not on the 12c508 because the 12 series uses the TRIS instruction to write to the TRIS register.

So, instead of
Code:
            BSF       03h,5 ;select page1 
            MOVLW  3e ;to make gp0 output 
            MOVWF  06 
            BCF       03h,5 ;select page0

You would use
Code:
                movlw   3eh
                tris    6

BTW, when you post code it is much easier if you use the code tag so that it formats correctly. Also, when you write code it is better to use labels rather than numbers. For example bsf STATUS,RP0 is instantly recognizable as a bank switch instruction whereas bsf 3,5 could be anything and requires a look at the datasheet to interpret it.

You should also add the include file to your code so you can use labels instead of numbers. Your code would then look something like this.
Code:
                processor       12c508a
#define         __12c508a
                include "p12c508a.inc"

FlashLED1       movlw   3eh
                tris    GPIO
Loop1           BSF     GPIO,0 ;select bit0 high 
                CALL    Delay1

You might also look at using the CBLOCK instruction to make your code even more readable.

HTH

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top