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.

my assembly lang is not working

Status
Not open for further replies.

Iawia

Member
hey all,

I am a beginner in assembly, and I just got done making my LED turn 'on', and am now trying to get the LED to flash with a period of ~1 Hz.
here is the code that I wrote, but the led stays 'on' the whole time.

as a coder of C++, java, assembly lang seems to be illogical at times and hard to follow, and I am failing to see why the LED is not flashing. Please help. I know there is other code out there that works, however I really want to know why THIS code doesn't work. I don't want to just copy and paste, but actually understand my error.

I am using the pic kit2 from Microchip, with the PIC12F508.
Open this .ASM with MPLAB IDE (but notepad and word will also work, but wont look as pretty)
thanks!
 

Attachments

  • Flash_LED.ASM
    3.7 KB · Views: 127
Last edited:
Hola Iawa,

Have you simulated it? I work always in Assembler but found it hard to follow.

Is it any chance that things are going SO fast that you do not see the OFF moments?

Had I that problem I would simulate it to know.
 
To toggle GP1

movlw 02
xorwf gpio,1

instead of
xorwf GPIO, f ;flip bit position at GP1
movwf GPIO ;place new output onto the pins


you don't have to:
clrf delay1 ;setting regs to 0 so we can start at 255 when using decfsz
clrf delay2

as they become zero after the first use.

you don't have to:
movlw b'000010'
movwf GPIO ;initialize GP1 to 'on'

as the program will toggle the on or off condition

All the sub-routines you need are here:

Library of routines for
PIC12F629 A-E E-P P
-Z
 
Last edited:
You just need to remove the line, movwf GPIO
Code:
flash
		xorwf	GPIO,f		;flip bit position at GP1
		movwf	GPIO		;<-----remove this	
		flash_outer		;~half second delay
		flash_inner 
		nop
		nop
		nop
		nop
		nop
		decfsz	delay1, f
		goto	flash_inner
		decfsz	delay2, f
		goto	flash_outer

		goto	flash

Putting ,f on the previous instruction places the result in the file, not W.

Mike.
 
yes, removing 'movwf GPIO' does make the program work. the led does flash. thanks!
i see that it is extremely important to know how each command works right down to which register is doing what and when it does and does not recieve data. how cumbersome!
do you guys know how to switch over to a C compiler in MPLAB?
and thanks for the library routines as well, they will come in handy.
 
i see that it is extremely important to know how each command works right down to which register is doing what and when it does and does not recieve data. how cumbersome!

I would use the term "accurate", or maybe "fast". Your C compiler will produce more lines of executable to accomplish the same task, which can wreck timing loops, make critically fast or synchronous routines impossible, and greatly reduce the amount of stuff you can get done on an underpowered little chip like the PIC12F508. Don't be too quick to give up on assembler for this one.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top