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.

pic program structure is confusing every writer makes his own !!

Status
Not open for further replies.

libyantiger

Member level 5
Joined
Aug 10, 2016
Messages
90
Helped
0
Reputation
0
Reaction score
3
Trophy points
1,288
Activity points
2,269
in this first stages of learning one is greatly confused when a difference is introduced in what is regarded as "STANDARD"


and what i am talking about is the configuration part of pic microcontroller in mplab ....where some writer can simply put in include(processor name )

followered by config statement which determine what the internal setp ups have to be switched on or off

for example wd timer off ...external oscillator is used ...etc


but some writers are making a file called header which have alot of pla pla pla


and within this file they include even a delay subroutine and within this header he sets some ports to inputs some outputs



its difficult to understand in many eBooks the delays subroutine are being done in the programs itself while in others are being put inside the header file


.....looks like there is no obvious standard structure every one making it on his own ,,,,it is cool but still i cant understand the limits of this

freedom ! where every thing can be put any where i bet if it was me who have done this the compiler would have shouted back at me


error!






this is program i am talking about





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
EQUATES SECTION
TMR0 EQU 1 ;means TMR0 is file 1.
STATUS EQU 3 ;means STATUS is file 3.
PORTA EQU 5 ;means PORTA is file 5.
PORTB EQU 6 ;means PORTB is file 6.
TRISA EQU 85H ;TRISA (the PORTA I/O selection) is file 85H
TRISB EQU 86H ;TRISB (the PORTB I/O selection) is file 86H
OPTION_R EQU 81H ;the OPTION register is file 81H
ZEROBIT EQU 2 ;means ZEROBIT is bit 2.
COUNT EQU 0CH ; COUNT is file 0C, a register to count events.
;*********************************************************
LIST P¼16F84 ;we are using the 16F84.
ORG 0 ;the start address in memory is 0
GOTO START ;goto start!
;******************************************************************
; Configuration Bits
__CONFIG H’3FF0’ ;selects LP oscillator, WDT off, PUT on,
;Code Protection disabled.
;*****************************************************
;SUBROUTINE SECTION.
; 1 second delay.
DELAY1 CLRF TMR0 ;START TMR0.
LOOPA MOVF TMR0,W ;READ TMR0 INTO W.
SUBLW .32 ;TIME - 32
BTFSS STATUS,
ZEROBIT ; Check TIME-W¼0
GOTO LOOPA ;Time is not¼32.
RETLW 0 ;Time is 32, return.
; 0.5 second delay.
Programming the 16F84 microcontroller 17
DELAYP5 CLRF TMR0 ;START TMR0.
LOOPB MOVF TMR0,W ;READ TMR0 INTO W.
SUBLW .16 ;TIME - 16
BTFSS STATUS,
ZEROBIT ; Check TIME-W¼0
GOTO LOOPB ;Time is not¼16.
RETLW 0 ;Time is 16, return.
;*********************************************************
;CONFIGURATION SECTION.
START BSF STATUS,5 ;Turns to Bank1.
MOVLW B’00011111;5bits of PORTA are I/P
MOVWF TRISA
MOVLW B’00000000’
MOVWF TRISB ;PORTB is OUTPUT
MOVLW B’00000111;Prescaler is /256
MOVWF OPTION_R ;TIMER is 1/32 secs.
BCF STATUS,5 ;Return to Bank0.
CLRF PORTA ;Clears PortA.
CLRF PORTB ;Clears PortB.
;*********************************************************
Program starts now.
BEGIN BSF PORTB,0 ;Turn ON B0.
CALL DELAYP5 ;Wait 0.5 seconds
BCF PORTB,0 ;Turn OFF B0.
CALL DELAYP5 ;Wait 0.5 seconds
GOTO BEGIN ;Repeat
END ;YOU MUST END






only at the very end the program started ? can some one tell us why not just config will do ...? and what is the limits of this freedom

where you can through every thing any where ?
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top