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.

Assembly Code Help. Pic 16f690

Status
Not open for further replies.

lmartinel

New Member
Hello everyone:

I am having a difficulty understanding what the following assembly code does:

bsf TRISA ^ 0X80,0

I comprehend that bst TRISA, 0 is enabling port pin AO as an input, but what the effect of ^0X80 is not understandable to me. Can anyone of you sharp guys help me. Thank you in advance
 
It's just a bodge to stops the assembler throwing up a warning. As long as you have the bank selection code around it then it will work with or without the ^0x80.

Mike.
 
Here some code that came with the pickit2 shows how it works
Code:
#include <p16F690.inc>
     errorlevel -302 
     __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
     org 0
Start:
     bsf     STATUS,RP0       ; select Register Page 1
     bcf     TRISC,0          ; make IO Pin C0 an output
     bcf     STATUS,RP0       ; back to Register Page 0
     bsf     PORTC,0          ; turn on LED C0 (DS1)
     goto    $                ; wait here
     end
 
Last edited:
Here I added a delay and made it blink
Code:
#include <p16F690.inc>
     errorlevel -302 
     __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
       cblock  0x20
	d1      ; Define three file registers for the
	d2      ; delay loop
	d3
        endc

     org 0
Start:
     bsf     STATUS,RP0       ; select Register Page 1
     bcf     TRISC,0          ; make IO Pin C0 an output
     bcf     STATUS,RP0       ; back to Register Page 0
     bsf     PORTC,0          ; turn on LED C0 
     call    Delay            ; delay so you can see the LED is on
     bcf     PORTC,0          ; turns off LED C0
     call    Delay            ; delay so Led will be off so you can see it blink
     goto    Start           ; wait here

Delay:
			;499994 cycles
	movlw	0x03
	movwf	d1
	movlw	0x18
	movwf	d2
	movlw	0x02
	movwf	d3
Delay_0:
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;2 cycles
	goto	$+1

			;4 cycles (including call)
	return

     end
 
Last edited:
Burt,

The code examples you have posted will both give a warning on the lines with TRIS on them. To get rid of the warnings you can either turn them off (errorlevel -302) or you can add the ^0x80 to the offending lines. You should of course check that the correct bank is selected before using either method.

Mike.
 
Here what i get when I build
Code:
 Debug build of project `C:\Pk2 Lessons\LPC Demo Board\02 Blink\myblink.mcp' started.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Mon Jun 22 22:55:25 2009
----------------------------------------------------------------------
Make: The target "C:\Pk2 Lessons\LPC Demo Board\02 Blink\myblink.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F690 "myblink.asm" /l"myblink.lst" /e"myblink.err" /d__DEBUG=1
Message[302] C:\PK2 LESSONS\LPC DEMO BOARD\02 BLINK\MYBLINK.ASM 12 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Make: The target "C:\Pk2 Lessons\LPC Demo Board\02 Blink\myblink.cof" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" /p16F690 "myblink.o" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"myblink.cof" /M"myblink.map" /W /x
MPLINK 4.30.01, Linker
Copyright (c) 2009 Microchip Technology Inc.
Errors    : 0

Loaded C:\Pk2 Lessons\LPC Demo Board\02 Blink\myblink.cof.
----------------------------------------------------------------------
Debug build of project `C:\Pk2 Lessons\LPC Demo Board\02 Blink\myblink.mcp' succeeded.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Mon Jun 22 22:55:32 2009
----------------------------------------------------------------------
BUILD SUCCEEDED
 
And this is what I get when I add
Code:
#include <p16F690.inc>
	errorlevel -302 
     __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
Code:
Debug build of project `C:\blink\blink.mcp' started.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Mon Jun 22 23:16:05 2009
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F690 "myblink.asm" /l"myblink.lst" /e"myblink.err" /d__DEBUG=1
Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" /p16F690 "myblink.o" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"myblink.cof" /M"myblink.map" /W /x
MPLINK 4.30.01, Linker
Copyright (c) 2009 Microchip Technology Inc.
Errors    : 0

Loaded C:\blink\myblink.cof.
----------------------------------------------------------------------
Debug build of project `C:\blink\blink.mcp' succeeded.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Mon Jun 22 23:16:09 2009
----------------------------------------------------------------------
BUILD SUCCEEDED
Looks better that way. That was kind of dum on my part seeing I new that would happen. It's like Mike said it"s just to remind you to check to make sure your in the
right bank after setting the Tris register
 
Last edited:
SPI with PIC16F690

Hi, anybody can showme an example to configure SPI on PIC16F690 in assembler??

Thanks in advances...
 
Maybe this will get you started
Code:
     BSF STATUS,RP0    ;Bank 1
     BCF STATUS,RP1     ;
LOOP
     BTFSS SSPSTAT, BF      ;Has data been received(transmit complete)?
    GOTO LOOP            ;No
    BCF STATUS,RP0     ;Bank 0
    MOVF SSPBUF, W     ;WREG reg = contents of SSPBUF
    MOVWF RXDATA      ;Save in user RAM, if data is meaningful
    MOVF TXDATA, W    ;W reg = contents of TXDATA
    MOVWF SSPBUF       ;New data to xmit
ericgibbs Thanks for the the post thats a great site
 
Last edited:
I am testing the PIC16F690 SPI communication with the TC72 temperature sensor in ISIS, but does not respond ... Any help would be greatly appreciated. This is my code:

ORG 0x0
INICIO
bsf STATUS,RP1
clrf ANSEL
clrf ANSELH
bcf STATUS,RP1
bsf STATUS,RP0
clrf PIE1
movlw b'00001000'
movwf TRISA
movlw b'00010000'
movwf TRISB
clrf TRISC
clrf SSPSTAT
movlw b'11000000'
movwf SSPSTAT
clrf INTCON
bcf STATUS,RP0
clrf SSPCON
movlw b'00100010' ;Config SPI, Frec SCK=fosc/64
movwf SSPCON

; bcf CS
TX
bsf CE ;Hab el Sen de Temp
movlw 0x80 ;Carga la Dir de Esc del Reg de Con
call BUSSPI
movlw 0x15 ;Carga el Modo de Medición
call BUSSPI
call Retardo_1s ;Espera la Conversión
LEER
movlw 0x02 ;Carga la Dir del Reg de Lect
call BUSSPI
call BUSSPI
movwf tmsb
call BUSSPI
movwf tlsb
bcf CE ;Deshab el Sen de Temp
call LCD

;Subrutina que maneja el bus SPI

BUSSPI
movwf SSPBUF
bsf STATUS,RP0
BUCLE
btfss SSPSTAT,BF
goto BUCLE
bcf STATUS,RP0
movf SSPBUF,w
return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top