Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F877A Assembly language Problem

Status
Not open for further replies.

vinothksr08

Member level 3
Joined
Jun 18, 2013
Messages
66
Helped
7
Reputation
14
Reaction score
7
Trophy points
8
Location
Tamilnadu, India
Activity points
367
Code:
#include "p16f877a.inc"
	ORG 0000H
	BCF TRISC,CCP1
	CLRF CCP1CON
	CLRF TMR2
	MOVLW D'249'
	MOVWF PR2
	MOVLW D'149'
	MOVWF CCPR1L
	MOVLW 0X2C
	MOVWF CCP1CON 
	MOVLW 0X01
	MOVWF T2CON
AGAIN 	BCF PIR1,TMR2ON
OVER	BTFSS PIR1,TMR2ON
	BRA OVER
	GOTO AGAIN
	END
the program shows error in MPLAB MPASM compiler
can anybody help me??

thank you...
 
Last edited by a moderator:

Replace BRA!!! its frescale or other mcu mnonic, use GOTO mnonic... See datasheet summary instruction set (page 160).
 
Last edited:

Hi,

If you get an error message its always better to show the errors with your code.

As Nagkiller says the BRA is a 18F assembly instruction not used in 16F assembly.

You also have the wrong bit specified PIR1,TMR2ON , I think should be TMR2IF ?

Seems like you are trying to set up a PWM but exactly what you are trying to do with the AGAIN loop not sure.

If you tell us what you are trying to achieve we can better help you.

As it stands your code needs a lot of reworking to allow it to run properly as you have missed many basic instructions needed to allow it to run as a complete program.
 

Hi,

If you get an error message its always better to show the errors with your code.

As Nagkiller says the BRA is a 18F assembly instruction not used in 16F assembly.

You also have the wrong bit specified PIR1,TMR2ON , I think should be TMR2IF ?

Seems like you are trying to set up a PWM but exactly what you are trying to do with the AGAIN loop not sure.

If you tell us what you are trying to achieve we can better help you.

As it stands your code needs a lot of reworking to allow it to run properly as you have missed many basic instructions needed to allow it to run as a complete program.

thank you ,
in basic assembly program, is there any changes in header file.?
 

I strongly advise you to start your program by copying the template file from Microchip and then adding your program to it. You could run into all sorts of strange problems as it is, even though the compiler may produce valid code.

Look for the file: C:\Program Files\Microchip\MPASM Suite\Template\Code\16F877ATEMP.ASM (assuming you installed in the normal folders) and copy the file to your work folder. Rename it to whatever you want to call it then add your code to it where indicated inside the file.

Brian.
 

Hi,

In addition to Brians comments, the tempate example of the 877a is not at good one as the Config Line will cause you problems.

Assuming you are using a Crystal oscillator of 4Mhz then use and OSC setting of XT and importantly the LVP should be OFF
Code:
list		p=16f877A	; list directive to define processor
#include	<p16f877A.inc>	; processor specific variable definitions
	
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

Also you need to understand that the System and User Registers are split over several 'banks'.
This means you have specify in your code which Bank the registers you are using are in.
banksel PR2 ; select bank 1
movwf PR2
banksel CCPR1L ; select bank 0

You also need to ensure the ports you are using as set to Digital, Input or Output - For PWM you need to ensure the appropriate pin is set to Output
 

Just a few small additions to the excellent advice given above:

1) When you get the template as Brian (#5) suggests, be sure to get temp, not tempo, assuming you are writing absolute code.
2) Configuration bits are well described in the datasheet. In MPLAB, you can also go to Configure > Configuration bits to review your choices and be sure the calculated hex code agrees with what you intend. I usually put the calculated hex as a comment in my program.
3) @post3: The enhanced 16F series (e.g., 16F1519) has the bra instruction and some others. As wp100 points out, the 16F877a and other non-enhanced 16F chips do not have that instruction.

John
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top