Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 9th August 2007, 02:45 AM   (permalink)
Default What am I doing wrong? (PIC ASM)

Okay, just to get myself back into having fun with PIC's, I wrote a little program to just make PORTA's bits turn on and off with a delay.

Code:
	#include P16F876A.INC

main	BSF	STATUS,5
	MOVLW	0x00
	MOVWF	TRISA
	BCF	STATUS,5

loop	CALL	delay
	COMF	PORTA
	GOTO	loop

delay	MOVLW	0x10
	MOVWF	0x20
cyc	DECFSZ	0x20
	GOTO	cyc
	RETURN
	
	END
The delay/cyc loop just sticks 16 in general register 0x20 and loops back to provide a delay for the rest of the loop, which just uses a COMF to (One would hope) invert all the bits in PORTA. But, it doesn't, which leads me to (correctly) assume that I've done something wrong.

In Proteus, it won't even do anything, and in Oshonsoft's PIC Simulator, it first turns all of PORTA on at the first iteration of the loop, but then only inverts one of the bits thereafter on each iteration. Could someone tell me what I did wrong? The code is simple, and seems solid...Maybe I'm just not using COMF correctly?
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk
Proud new owner of a Cloudbook (512MB DDR2, 1.2Ghz C7-M, Windows XP Pro SP3)
And PIC16 ASM purist (Who needs BASIC and C for these chips? NOT ME!
ArtemisGoldfish is offline   Reply With Quote
Old 9th August 2007, 05:04 AM   (permalink)
Default

Maybe you need an ORG and a CONFIG line. Also, isn't port A configured as analogue by default?

Mike.
Pommie is online now   Reply With Quote
Old 9th August 2007, 06:14 AM   (permalink)
Default

Quote:
Originally Posted by Pommie
Maybe you need an ORG and a CONFIG line. Also, isn't port A configured as analogue by default?

Mike.
The CONFIG line isn't needed for simulation (as far as I know), and the step-by-step debugger looks solid...But the thing just doesn't work as I'd expect it to.
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk
Proud new owner of a Cloudbook (512MB DDR2, 1.2Ghz C7-M, Windows XP Pro SP3)
And PIC16 ASM purist (Who needs BASIC and C for these chips? NOT ME!
ArtemisGoldfish is offline   Reply With Quote
Old 9th August 2007, 06:37 AM   (permalink)
Default

You need to switch port A to digital.

Try,
Code:
main	BSF	STATUS,5
	MOVLW	0x06	; Configure all pins
	MOVWF	ADCON1	; as digital inputs
	MOVLW	0x00
	MOVWF	TRISA
	BCF	STATUS,5
You can output bits with the port set as analogue but any reads will return zero. Your complement will therefore always read zero and always write 0xff. RA4 is the exception as it is not an analogue input.

Mike.

Last edited by Pommie; 9th August 2007 at 06:52 AM.
Pommie is online now   Reply With Quote
Old 9th August 2007, 06:57 AM   (permalink)
Default

hi,
This will run on your Oshonsoft Simulator & MPLAB, as Pommie states, you missed ADCON1

Code:
;USED WITH OSHONSOFT SIM

		list      p=16f876A
	#include <p16f876A.inc>

 	errorlevel -302, -207

 __CONFIG _CP_OFF & _XT_OSC & _PWRTE_ON  & _WDT_OFF & _LVP_OFF  & _DEBUG_OFF



main:	BSF	STATUS,RP0
	MOVLW 0X07
	MOVWF ADCON1
	MOVLW 0X00
	MOVWF TRISA
	BCF STATUS,RP0



loop:	CALL	delay
	COMF	PORTA,F
	GOTO	loop

delay:	MOVLW	0x10
	MOVWF	0x20
cyc:	DECFSZ	0x20,F
	GOTO	cyc
	RETURN
	
	END
Eric

Last edited by ericgibbs; 7th July 2008 at 11:21 AM.
ericgibbs is offline   Reply With Quote
Old 9th August 2007, 04:44 PM   (permalink)
Default

You guys kick ass, thanks :-)

Update: And it even works perfectly in Proteus.
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk
Proud new owner of a Cloudbook (512MB DDR2, 1.2Ghz C7-M, Windows XP Pro SP3)
And PIC16 ASM purist (Who needs BASIC and C for these chips? NOT ME!

Last edited by ArtemisGoldfish; 9th August 2007 at 04:48 PM.
ArtemisGoldfish is offline   Reply With Quote
Old 10th August 2007, 12:51 AM   (permalink)
Default

May I sugget to make a template asm file for each microcontrolle partnumber. Put every bit, flag, value, and meaning to all SFRs at the top. Pull from this template at the start of a new project and remove unessential code as desired.

Similar to this but not like this:
Code:
        LIST    P=16F648
         INCLUDE "P16F648A.INC"
	INCLUDE "SHORTS.INC"
        __CONFIG _LVP_OFF & _MCLRE_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _CP_ON & _WDT_OFF & _PWRTE_OFF
        ERRORLEVEL -302        

        
	CBLOCK 0X20 ; TEMPORARY STORAGE-------------
	CNTJ, CNTK, CNTP1, CNTP2, CNTP3, CNT1, CNT2, W_REG, STATUS_REG
         PORTB_TEMP, MS_TIME, MS_TIME_TEMP, DEB_CNT, DECOUNT
	;------------THIS PROGRAM NEEDS...---------
	SDELAYCOUNT
	ENDC ;--------TEMPORARY STORAGE-------------

	ORG	0X04
START:	;-----PORT I/O CONFIGURATION-------------------------------
         BANK0
	BSF	CMCON, CM2		;DISABLE COMPARATOR.
	BSF	CMCON, CM1		
	BSF	CMCON, CM0
	BANK1
         LOADF    TRISA, B'11110111'
         LOADF    TRISB, B'00000000'
         BSF	OPTION_REG, NOT_RBPU	;BCF/BSF = ENABLE/DISABLE PULL-UP.
	BCF	OPTION_REG, INTEDG 	;BSF/BCF = HIGH/LOW - RB0/INT EDGE TRIGGER
		;------POWER ON RESET CONFIGURATION--------------------------
	BSF	PCON, OSCF	;C/S = 37KHZ/4MHZ     OSCILLATOR SPEED.
	BANK1	;------INTERRUPT CONFIGURATION-------------------------------
	BCF	INTCON, PEIE	;C/S = DIS/ENABLE     PERIPHERAL INTERRUPTS.
	BCF	PIE1, TMR1IE  	;C/S = DIS/ENABLE     TIMER1     INTERRUPT.
	BCF	PIE1, CCP1IE	;C/S = DIS/ENABLE	    CAPTURE    INTERRUPT.
	BCF	PIE1, CMIE	;C/S = DIS/ENABLE	    COMPARATOR INTERRUPT.
	BCF	PIE1, EEIE	;C/S = DIS/ENABLE	    EEPROM     INTERRUPT.
	BCF	INTCON, GIE  	;C/S = DIS/ENABLE     GLOBAL     INTERRUPT.
	BCF	INTCON, T0IE	;C/S = DIS/ENABLE	    TIMER0     INTERRUPT.
         BANK0	;----TIMER1 CONFIGURATION-----------------------------------
	BCF	T1CON, TMR1ON 	;C/S = DIS/ENABLE     	     TIMER1 ON.
	BCF	T1CON, TMR1CS 	;C/S = IN/EXTERNAL(RA6)   		CLOCK.
         BANK1	;----TIMER0 CONFIGURATION-----------------------------------
	BCF	OPTION_REG, T0CS	;C/S = IN/EXTERNAL(RA4)   		CLOCK.
	BCF	OPTION_REG, PSA	;C/S = TIMER0/WDT    PRESCALER ASSIGNMENT.
	BCF	OPTION_REG, .2	;PRESCALER
	BCF	OPTION_REG, .1	;000=1:2,  001=1:4,  010=1:8,   011=1:16
	BCF	OPTION_REG, .0	;100=1:32, 101=1:64, 110=1:128, 111=1:256
	BANK0	;-------------------------------------------------------------
;*********MAIN**************************
	CLRF	PORTB

MAIN:
donniedj is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
555 not timing,what am I doing wrong? markelectro Electronic Projects Design/Ideas/Reviews 14 4th August 2007 01:42 PM
need help modifying some pic ASM code justDIY Micro Controllers 17 16th July 2007 11:41 AM
Integrating PIC ASM as a callable function from C18 toodles Micro Controllers 2 3rd July 2007 12:01 AM
Circuit layout for connecting PS/2 port to a PIC? ChemE Electronic Projects Design/Ideas/Reviews 11 25th April 2007 12:49 AM
Newcomers, please read! (PIC regarded) Upd. 0xD Jay.slovak Micro Controllers 0 17th April 2005 01:04 PM



All times are GMT. The time now is 11:04 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.