First Code Ever...

Status
Not open for further replies.

striker2509

New Member
Hi everyone, I would like to know if u can take a look into this program, may work allright, or not?. if you people can give me some advice, it will be well taken. Im beginning program to these PICS and i find the fascinating. Any help will be nice.....Greatings....Thanks

P.D.: This is my first program, receive a 4 bit data on port C (less significant bits) and put those 4 bits on PortB LSB. When its done, the program activate a demux enable (74LS154). And the demux do the rest...This is controlling 3 demux....as a final project, i have to control about 25 i guess....thanks again.....see ya
 

Attachments

  • program.txt
    2.7 KB · Views: 215
I made the ff. changes:

1. Added the line: "LIST P=16F877"
2. Replaced instances of ",0" and ",1" with ",W" and ",F" respectively.
3. Please see the ASSIGN routine.

Take time to read the contents of the file "PIC16F877.INC". In there you will find all the predefined constants relevant to the PIC16F877. Make use of the predefined constants like W, F and others. Using the constants will make your code easier to read and less prone to errors. In addition, it will make your program easier to adapt to other PIC devices & families like the PIC18F family.

Code:
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;	Author: Rafael Franceschi							:
;	Date: 02/06/05										:
;	Version: 2.7										:
;	Title: Prueba 2 ( 7 modificaciones )					:
;	Description: Toma la senal de entrada del puerto C	:
;				y la coloca en el puerto de salida B,		:
;				senales TTL (High and Low tanto en la	:
;				entrada como en la salida)				:
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::

; You forgot to put the ff. line before the include.
            LIST P=16F877

			INCLUDE	"P16F877.INC"

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

;****************set up the constants****************
;*** Some of the constants are already defined in "PIC16F877.INC"
;STATUS	EQU	03h     
;TRISB	EQU	86h
;TRISC	EQU	87h
;PORTB	EQU	06h
;PORTC	EQU	07h
COUNT1	EQU	21h
COUNT2	EQU	22h
TEMP	EQU	23h
		    
			ORG			0x00
			GOTO		CONFIGURATION

CONFIGURATION
			BSF			STATUS,5				;Go to bank 1
			CLRF		TRISB					;Put 00 into TRISB - all pins set to output
			MOVLW		b'00001111'				;Put 255 into W
			MOVWF		TRISC					;Put 255 into TRISC - RC0/RC3 set as input
			BCF			STATUS,5				;Come back to bank 0	


			CALL 		DIRECCION1
			CALL		DIRECCION2
			CLRF		PORTB
			CLRF		PORTC
				

START		CALL		INITIALIZE
			CALL		LOOP1
			CALL		ASSIGN
			CALL		ACT_ENABLE1
			CALL		ACT_ENABLE2
			CALL		LOOP2
			GOTO 		START

;************Start of Delay 1***********************************			
LOOP1		DECFSZ		COUNT1,F		;Substract 1 from 255 - initial value of register 21h
			GOTO		LOOP1					;If COUNT1 is Zero, jump this instruction
			CALL		DIRECCION1
			RETURN

;***********Add Another OFF delay********************************
LOOP2		DECFSZ		COUNT2,F			;Substract 1 from 255 - initial value of register 22h
			GOTO		LOOP2					;If COUNT1 is Zero, jump this instruction
			CALL 		DIRECCION2
			RETURN

;************Subroutines Counters*********************************
DIRECCION1	MOVLW		.50					;Counter time - from "x" to zero
			MOVWF		COUNT1
			RETURN

DIRECCION2	MOVLW		.50					;Counter time - from "x" to zero
			MOVWF		COUNT2
			RETURN

;*************Initialize the ports and comands********************
INITIALIZE	BSF			PORTC,5
			BSF			PORTC,6
			BSF			PORTC,7
			CLRF		PORTB
			CLRW
			RETURN
;*************Enable the demuxs (2 at first)**********************
ACT_ENABLE1	BCF			PORTC,5				;Clears Enable Bit - Activates First Enable
			RETURN

ACT_ENABLE2	BCF			PORTC,6				;Clears Enable Bit - Activates Second Enable
			RETURN

;*************Assigning the Vectors*******************************

ASSIGN		MOVF		PORTC,W
			ANDLW		b'00001111'
			MOVWF		TEMP
			MOVF		PORTB,W
			ANDLW		b'11110000'
			IORWF		TEMP,W
			MOVWF		PORTB
			RETURN
;**********************END of Program****************************				
			END
 
HI AGAIN

im using MPLAB from microchip.....and when i compile it....it keeps having a warning...the message says

Message[302] C:\PRUEBA27.ASM 32 : Register in operand not in bank 0. Ensure that bank bits are correct.

i know that i configure the register in bank 1....but the program keep saying that...should i be worried about that?
 
It's just a friendly reminder to set the appropriate bank register bits. Use the ff. line near the beginning of your program to suppress it.

Code:
         ERRORLEVEL    -302
 
Re: HI AGAIN


It's only a warning, not an error - if you like you can disable it by including the line 'errorlevel -302', see the details for errorlevel in the helpfile.

The assembler isn't clever enough to know that you have already selected the correct bank, so either ignore it, or disable it.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…