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.

Assembly Language for PIC16f877a

Status
Not open for further replies.

amitnegi2008

Newbie level 1
Joined
May 3, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,343
i am currently using assembly language for my Final Year Project. Then i use MPLAB to convert the assembly code to hex code but it did not work.My project is Program in Microcontroller PIC 16F877A for DC Motor Speed Control interfacing with pc.
this is the code........
Program in Microcontroller PIC 16F877A for DC Motor Speed Control


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
;===============================================================
; File name : psm.asm
; Project : Dc Motor Speed Control by Using Microcontroller PIC16F877A
;===============================================================
list p=16f877A ; list directive to define processor
ERRORLEVEL -302
ERRORLEVEL -305
#include <p16f877A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF
;============= HARDWARE CONNECTION===========================
; Crystal - 20MHZ
; Capacitor - 22pF
; RB1(PIN34) & RB2 (PIN35) - CONNECT TO L298(H,L)
; CCP2 (PIN16) - CONNECT TO ENABLE L298
; RA0 as speed counter
;===============================================================
;===============MACRO CHANGE BANK ============================
BANK0 MACRO ;Change to BANK0
BCF STATUS,RP0
BCF STATUS,RP1
ENDM
BANK1 MACRO ;Change to BANK1
BSF STATUS,RP0
BSF STATUS,RP1
ENDM
;===============================================================
;Set up initialize value and cblock for the variables needed.
BAUD_RATE EQU 0X81 ;Set Baud Rate 9600 for 20MHZ for USART
Communication
CBLOCK 0X20
D1 ;For Delay
D2 ;For Delay
D3 ;For Delay
X1 ;For Counter
X2 ;For Gain
REFERENCE ;For Reference Speed
CHANGE ;For error correction
ENDC
;-----------------------------------------------------------------------------------------------------------
ORG 0x00
GOTO MAIN
ORG 0x04
GOTO INT ;Interrupt Process
;------------------------------------------------------------------------------------------------------------
;============== MAIN PROGRAM ===================================
MAIN BANK0
CALL INIT ; Intialization
STANDBY CALL SERIALSCAN ; Get data for reference speed
MOVF REFERENCE,W
SUBLW 0X00
BTFSC STATUS,Z ; Reference speed = 0?
GOTO STANDBY ; Yes. Get data again
MOVLW D'30' ; Set Timer1 as 30*13.107ms = 0.39321
where X2 as gain
MOVWF X2
;------------------------------- RA0 - AS SPEED COUNTER -----------------------------------------
LOOP BTFSS PORTA,0
GOTO $-1
CALL CHECKNOISE
BTFSC PORTA,0
GOTO $-1
BTFSS PIR1,TMR1IF
GOTO LOOP
;Check Noise function
CHECKNOISE CALL DELAY1 ;If bandwith is less than 1ms, then it is noise
BTFSC PORTA,0
INCF X1,1 ;Not noise, increase counter
RETURN
;=================================================================
;##########################INITIALIZATION################################
INIT BANK0
CLRF PORTA
CLRF PORTB
CLRF PORTC
CLRF PORTD
CLRF X1
CLRF X2
CLRF REFERENCE
70
;---Initialize PORT----------------------------
BANK1
MOVLW 0x06
MOVWF ADCON1 ;PortA as digital input
MOVLW 0xFF ;PortA as input
MOVWF TRISA
MOVLW 0x00 ;Set PortB as output
MOVWF TRISB
BANK0
BSF PORTB,1 ;RB1,RB2(pin 34 and 35) sambung ke
pin 10 dan 12 of L298
BCF PORTB,2
;----Initialize PWM-----------------------------
BANK1
MOVLW 0xFF ;PWM Setup: Period KHZ(19.152KHZ)
MOVWF PR2
BCF TRISC,1
BCF TRISC,2
BANK0
CLRF TMR2
MOVLW 0X00 ;Duty Cycle = 0%
MOVWF CCPR2L
MOVLW 0x04 ;ON TMR2, PRESCALE = 1
MOVWF T2CON
MOVLW 0x0C
MOVWF CCP2CON ;PWM Mode
;-----Set TIMER1 AS TIMER MODE------------------
BANK0
MOVLW 0X00
MOVWF TMR1H ;Timer= 0000-FFFFH =
; 65535*1/(20M/4)=13.107ms
MOVLW 0X00
MOVWF TMR1L
MOVLW b'00000001' ;Pre=1:1 TMR1=Int TMR1=ON MOVWF T1CON
BANK1
MOVLW b'00000001' ;TMR1IE=1
MOVWF PIE1
BANK0
MOVLW b'11000000' ;GIE=1, PEIE=1
MOVWF INTCON
;------Set up Serial Port-----------------------
SERIAL_SETUP: BANK1
MOVLW 0XC0 ;RC6&7->Input,Others output
IORWF TRISC,F ;Keep in file register
MOVLW BAUD_RATE
MOVWF SPBRG
71
MOVLW 0X24
MOVWF TXSTA ;Enable transmission & high baud rate
BANK0
MOVLW 0X90
MOVWF RCSTA ;Enable srial port & continuous reception
RETURN
;######################## END OF INITIALIZATION##########################
;^^^^^^^^^^^^^^^^^^^^^^^^ SUBROUTIONE^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;-----------Correction of Overrun Error--------------
OVERRUN_ERROR BCF RCSTA,CREN ;Disable continuous reception
BSF RCSTA,CREN ;Enable continuous reception
RETURN
;-----------Correction of Framming Error------------
FERR_ERROR MOVF RCREG,W ;Discard Framming Error
RETURN
;----------Send the detect speed to PC-------------
SERIAL_TRANSMIT: BTFSS PIR1,TXIF ;Check if data TXREG is transfer
to TSR ->TXREG is empty
GOTO $-1
MOVWF TXREG
RETURN
;-----------Get data for reference speed -------------------
SERIALSCAN CALL OVERRUN_ERROR ;Correction of Overrun Error
CALL FERR_ERROR ;Correction of Framming Error
BTFSS PIR1,RCIF ;Check if data receive
GOTO $-1 ;Wait until new data
MOVF RCREG,W ;Get received data to W
MOVWF REFERENCE
RETURN
;------------Short Delay-----------------------------------------
DELAY1 MOVLW D'5' ;PAUSE FOR ABOUT 1mS
MOVWF D3
MOVLW D'9'
MOVWF D2
MOVLW D'36'
MOVWF D1
DECFSZ D1
GOTO $-1
72
DECFSZ D2
GOTO $-5
DECFSZ D3
GOTO $-9
RETURN
DELAY2 MOVLW D'255' ;PAUSE FOR ABOUT 1mS
MOVWF D3
MOVLW D'255'
MOVWF D2
MOVLW D'36'
MOVWF D1
DECFSZ D1
GOTO $-1
DECFSZ D2
GOTO $-5
DECFSZ D3
GOTO $-9
RETURN
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;*********************** INTERRUPT PROCESS******************************
INT CLRF PIR1 ; Clear interruption flag
DECFSZ X2,F ; Haven't reach 0.799527s
GOTO CONTINUE ; Continue counter
GETDATA MOVF X1,W ; Get value of counter,detect speed
SUBWF REFERENCE,W ; Ref speed - Detect speed
MOVWF CHANGE ; CHANGE = error correction
BTFSC STATUS,C ; Reference < Detect ?
GOTO GREATER ; No. Jump to > or = check
LESS MOVF CHANGE,W
ADDWF CCPR2L,F ; Add duty cycle with error correction
GOTO SHOWSPEED
GREATER BTFSC STATUS,Z ; Reference = Detect?
GOTO SHOWSPEED ; Yes, no need correction.
MOVF CHANGE,W ; Detect speed > ref speed, decrease
duty cycle with error correction
SUBLW 0XFF; Convert the negative value to positive value
SUBWF CCPR2L,F
SHOWSPEED MOVF X1,W
CALL SERIAL_TRANSMIT
CALL OVERRUN_ERROR ;Correction of Overrun Error
CALL FERR_ERROR ;Correction of Framming Error
CLRF X1 ;Reset Counter
73
MOVLW D'30' ;Reset Timer
MOVWF X2
CALL SERIALSCAN ; Get data for reference speed
MOVF REFERENCE,W
SUBLW 0X00
BTFSS STATUS,Z ; Reference speed = 0?
GOTO CONTINUE ; No, continue the process
STOPMOTOR MOVLW 0X00 ; Yes. Stop motor
MOVWF CCPR2L
CALL DELAY2
CONTINUE RETFIE
;******************** END OF INTERRUPT PROCESS*************************
END
;-------------------------------------END OF PROGRAM------------------------------------------------



please help me to remove the error.
 
Last edited by a moderator:

Please describe the errors in detail and post any error listings/reports available.

Are these errors, Assembler or Runtime errors?

BigDog
 

Hi BDG

Had MPlab running so just compiled the code, seems there are 4 numbers 70 to 73 across the code without any obvious clue as to what they are.

Think amitnegi2008 needs to show where the code comes from so we can see what its supposed to be, looks spurious to me ..?

Code:
	MOVLW BAUD_RATE
	MOVWF SPBRG
	[B]71[/B]
	MOVLW 0X24

INIT BANK0
	CLRF PORTA
	CLRF PORTB
	CLRF PORTC
	CLRF PORTD
	CLRF X1
	CLRF X2
	CLRF REFERENCE
[B]	70[/B]
	;---Initialize PORT----------------------------
 

In amitnegi2008's original listing the numbers in question are in numerical order, perhaps they were page/listing numbers inadvertently copied and pasted.

In any event, I agree amitnegi2008 needs to elaborate on the origin of the code, its intended task and the specific errors to which he is referring.

The request:

please help me to remove the error.

is inadequate.

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top