PDA

View Full Version : Port A pins



Eric123
- 11th July 2006, 14:32
I am just getting into microcontroller programing and am haveing trouble geting the port A pins to go high and low. I dont really understand how to get thoes pins to go high and low. My micorcontroller is a pic16f84. If someone could give me the assembly code to make a specific A pin go high, and descrive exactly what is going on in the code I would appreciate it.

Thanks

mister_e
- 11th July 2006, 16:05
Few start point
http://www.picbasic.co.uk/forum/showthread.php?t=542&highlight=dummies





; Super dooper LED blink with 10F200
; ==================================
; Steve Monfette
; Mister E
; 23/03/2006

; As if the world really needed it... well it's still usefull
; to learn a bit how to play and waste your time using the
; annoying assembler language. BTW 10F200 are just too small
; to accept any other language.

; This program will use a software loop delay, called by a macro
; wich will pass the delay to produce... at least not too basic and
; some part could be usefull.. one day if someones really try to figure
; out how it works... just kidding.. i know EVERYBODY WILL TRY ;o)
; ---------------------------------------------------------------------

INCLUDE "P10F200.INC" ; load all needed stuff

; PIC configuration
; =================
__Config _MCLRE_ON & _CP_OFF & _WDT_OFF

; Hardware assignement
; ====================
#define Led GPIO,2

; RAM assignement
; ===============
; hands-up those who discover figure 4-3

cblock 0x10
loop
UserDelay
endc

; Macro Definition
; ================
; Be carefull, the following macro is extremely difficult to understand
; and contain tons of information... always refer to MPASM book to
; understand all trick it do.. mpff mkay i stop it :o)

; Nothing fancy, the macro will just pass the parameter to the 1 msec
; subroutine -> Delay <- Not much. What could she do more to be still
; code efficient anyway?

Delayms macro User
movlw User ; put User wish somewhere
movwf UserDelay ; copy it to something
call Delay ; do the delay
endm

; ///////////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; Program Begining
; ///////////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

; Hardware configuration
; ======================
ORG 0 ;
movwf OSCCAL ; Load OSCCAL value

movlw b'11111011' ;
TRIS GPIO ; Set GP2 as Output

movlw b'11011111' ; TOCS=internal => to use GP2 as Output
OPTION ; => datasheet section 4.5

; Tha ****!
; =========
; The exciting part of the program... how to blink a LED
Start
bsf Led ; Enable LED
Delayms d'250' ; do 250 mSec Delay
bcf Led ; Disable LED
Delayms d'250' ; do 250 mSec Delay
goto Start ; Have fun forever, enjoy the show

; Delay Subroutine
; ================
; The main program call the macro, the macro call this routine
Delay
movlw d'250' ; 1 mSec base
movwf loop ; loop

; DelayLoop
; ---------
nop ; do nothing (1 Cycle)
decfsz loop,f ; base loop finished? (1 cycle if NO, 2 cycle if YES)
goto $-2 ; NO... jump 2 lines before (2 cycles)
; -------------------------------
; Killed about 4 cycles * 250times @1uSec = 1mSec
;
decfsz UserDelay,f ; DelayFinish?
goto $-6 ; NO... do it again, jump 6 line before
retlw 0 ; Astalavista baby
end

AMay
- 21st August 2006, 22:13
Perhaps you have figured it out by now.

Anyway, use "poke" + the "A" register + a binary discription of how you want the 4 pins.

If you want them all high:

POKE $5,%1111

All low:

POKE $5,%0000

mister_e
- 22nd August 2006, 03:25
i guess you misread the following part ;)

If someone could give me the assembly code to make a specific A pin go high, and descrive exactly what is going on in the code I would appreciate it.