PIC16F876A - Banks - Assembly

Discussion in 'Programming General' started by me_person666, May 1, 2013.

PIC16F876A - Banks - Assembly
  1. Unread #1 - May 1, 2013 at 10:31 PM
  2. me_person666
    Joined:
    Aug 13, 2008
    Posts:
    425
    Referrals:
    0
    Sythe Gold:
    0

    me_person666 Forum Addict

    PIC16F876A - Banks - Assembly

    I'm confused on a question i have in my homework assignment, it states;

    Code:
    What does PIC16F976A "BANKS" mean? Why does it need "banks"? How does it select banks?
    I know how to change banks in assembly, but i'm a little confused on the exact definition of a bank. For what i can think of is that a bank is sort of like a location on the processor, where it loads different commands. Sort of like grouping them into different area's.

    I have no idea how to answer it. Please help me here. I'm a microprocessor noob.



    Also, how can i make it reset after every time i press the reset button? I have the loops to "Pause it"(EDIT WELL I DID BUT I WAS PLAYING WITH IT) But how to i make it so it resets every time i press a button at any time? Is there an easier way of doing it instead of putting a GOTO loop after every LED flash?

    Code:
    	list		p=16f876A		; list directive to define processor
    	#include	<p16f876A.inc>		; processor specific variable definitions
    	
    	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
    
    ; '__CONFIG' directive is used to embed configuration data within .asm file.
    ; The labels following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.
    
    
    
    
    
    
    ;***** VARIABLE DEFINITIONS
    
    w_temp		EQU	0x71		; variable used for context saving 
    status_temp	EQU	0x72		; variable used for context saving
    pclath_temp	EQU	0x73		; variable used for context saving		
    
    
    	ORG	0x20
    DVAR0		EQU 	0x20		; Variable used in delay loop (inner counter #)
    DVAR1		EQU	0x21		; variable used in delay loop (middle counter #)
    DVAR2		EQU 	0x22		; variable used in delay loop (outer counter #)
    	
    
    
    ;**********************************************************************
    	ORG     0x000          	; processor reset vector
    
    	nop			; nop required for icd
      	goto    main           	; go to beginning of program
    
    
    	ORG     0x004          	; interrupt vector location
    
    	movwf   	w_temp         		; save off current W register contents
    	movf		STATUS,w        	; move status register into W register
    	movwf		status_temp     	; save off contents of STATUS register
    	movf		PCLATH,w	  	; move pclath register into w register
    	movwf		pclath_temp	  	; save off contents of PCLATH register
    
    ; isr code can go here or be located as a call subroutine elsewhere
    
    	movf		pclath_temp,w	  	; retrieve copy of PCLATH register
    	movwf		PCLATH		  		; restore pre-isr PCLATH register contents
    	movf    	status_temp,w     	; retrieve copy of STATUS register
    	movwf		STATUS            	; restore pre-isr STATUS register contents
    	swapf   	w_temp,f
    	swapf   	w_temp,w          	; restore pre-isr W register contents
    	retfie                    		; return from interrupt
    
    
    
    main
    
    ; remaining code goes here
    
    
    Init
    
    	bsf		STATUS, RP0  		; select Bank1. (RP0 and RP1 are "0" by default)
    
    	movlw		0x47			; W.REG = 01000111B
    	movwf		ADCON1			; set up all pins of PORTA as digital pins 
    
    	movlw		0x0F			; W.REG = 00001111B
    	movwf		TRISA			; set up input pins (RA3-RA0) and output pins (RA5-RA4) of PORTA.
    		
    	movlw		0x40			; W.REG = 01000000B
    	movwf		TRISB			; set up PORTB. Input pins: RC6; Output pins: RB7, RB5-RB0 
    
    	movlw		0xA3			; W.REG = 10100011B
    	movwf		TRISC			; set up PORTC. Input pins: RC7, 5, 1, 0; Output pins: RC6, RC4-RC2
    
    
    	bcf		STATUS, RP0  		; select Bank0.
    
    
    Loop
    
    	btfss		PORTC, RC5		; check RC5 (the button). If it is "1", skip the next line (instruction)
    	goto		Loop			; If RC5=0, halt there and continue to check RC5 bit until it is"'1", i.e. the button is released
    
    	
    	call 		Hello			; call "Hello" subroutine, which turns L-LED on & R-LED off for 0.5 seconds
    						; and then turns L-LED off & R-LED on for 0.5 seconds.
    	call		Howareyou
    
    	call		Imverywellthanks
    
    	call		hahahahahah
    
    	goto		Loop			; Check RC5 bit (the switch) if it is pressed down.
    
    
    
    
    Hello
    	Loop1
    	btfss		PORTC, RC5
    	goto		Loop
    
    	bcf		PORTA, RA4		; RA4=0 to turn on  L-LED  (active LOW)
     	bsf		PORTA, RA5		; RA5=1 to turn off R-LED  (active LOW)
    
    	call	Delay			; Delay 0.5 seconds
    
    	bsf		PORTA, RA4		; RA4=1 to turn off L-LED (active LOW)
     	bcf		PORTA, RA5		; RA5=0 to turn on  R-LED (active LOW)
    
    	call	Delay			; Delay 0.5 seconds
    	
    
    	return
    
    Howareyou
    	Loop2
    	btfss		PORTC, RC5
    	goto		Loop
    
    	bcf	 	PORTA, RA4			; RA4=0 to turn on  L-LED  (active LOW)
    	bsf		PORTA, RA5			; turn led right off
    
    	call	Delay				;delay for 0.5
    	
    	bsf		PORTA, RA4			; ra4 = 0 turn on left led
    
    	call	Delay				;delay for 0.5
    
    	bcf		PORTA, RA4			; ra4 = 0 turn on left led
    
    	call	Delay				;delay for 0.5
    	
    	bsf		PORTA, RA4			; ra4 = 0 turn on left led
    
    	call	Delay				;delay for 0.5
    
    	bcf		PORTA, RA4			; ra4 = 0 turn on left led
    	
    	call	Delay				;delay for 0.5
    
    	bsf		PORTA, RA4
    	
    	call	Delay				; delay for 0.5secs
    
    
    
    	return
    
    Imverywellthanks
    	Loop3
    	btfss		PORTC, RC5
    	goto		Loop
    
    	bcf		PORTA, RA5			;right led on
    	bsf		PORTA, RA4			;left led off
    
    	call	Delay
    	
    	bsf		PORTA, RA5			;right led off
    
    
    	call	Delay
    
    	bcf		PORTA, RA5			;right led on
    
    
    	call	Delay
    	
    	bsf		PORTA, RA5			;right led off
    
    
    	call	Delay
    
    	bcf		PORTA, RA5			;right led on
    	
    	call	Delay
    	
    	bsf		PORTA, RA5			;right led off
    
    
    	call	Delay
    
    	bcf		PORTA, RA5			;right led on
    
    	call	Delay
    	
    	bsf		PORTA, RA5			;right led off
    
    	call	Delay
    
    
    	return
    
    hahahahahah
    	Loop4
    	btfss		PORTC, RC5
    	goto		Loop
    
    	bcf		PORTA, RA5			;turn right led on
    	bcf		PORTA, RA4			;turn left led on
    
    	call	Delay
    
    	bsf		PORTA, RA5			;turn right led off
    	bsf		PORTA, RA4			;turn left led off
    
    	call	Delay
    
    	bcf		PORTA, RA5			;turn right led on
    	bcf		PORTA, RA4			;turn left led on
    
    	call	Delay
    
    	bsf		PORTA, RA5			;turn right led off
    	bsf		PORTA, RA4			;turn left led off
    
    	call	Delay
    
    	bcf		PORTA, RA5			;turn right led on
    	bcf		PORTA, RA4			;turn left led on
    
    	call	Delay
    
    	bsf		PORTA, RA5			;turn right led off
    	bsf		PORTA, RA4			;turn left led off
    
    	call	Delay
    
    	
    
    	return
    
    Delay
    	movlw		0x14			; set outer delay loop to 500 ms (20*25 ms, 0X14=20d)
    	movwf		DVAR2			; move 0x10 into VAR2 variable
    
    Delay0
    	movlw		0xFA			; set middle delay loop to 25 ms (250*100 us, 0XFA=250d)
    	movwf		DVAR1			; move 0xFF into VAR1 variable
    
    Delay1
    	movlw		0xA5			; set inner delay loop to 100 us (use stop watch tested, 0XA5=165)
    	movwf		DVAR0			; move 0xFF into VAR0 variable
    
    Delay2
    	decfsz		DVAR0			; DAVR0=DAVR0&#8211;1 and skip next instruction if DAVR0=0
    	goto		Delay2			; loop to Delay2
    	
    	decfsz		DVAR1			; DAVR1=DAVR1&#8211;1 and skip next instruction if DAVR1=0
    	goto		Delay1			; loop to Delay1
    
    	decfsz		DVAR2			; DAVR2=DAVR2&#8211;1 and skip next instruction if DAVR2=0
    	goto		Delay0			; loop to Delay0
    
    	return					; return to where &#8220;call delay&#8221; happened&#8221;
    
    
    	END                       		; directive 'end of program'
     
< C++ Homework | Modular IRC bot in Python using irclib >

Users viewing this thread
1 guest


 
 
Adblock breaks this site