/home/gerhard/MPLABXProjects/ASSR/PIC_ASM_Test_2.X/asm_test.asm
  1 ;*******************************************************************************
  2 ;                                                                              *
  3 ;    Microchip licenses this software to you solely for use with Microchip     *
  4 ;    products. The software is owned by Microchip and/or its licensors, and is *
  5 ;    protected under applicable copyright laws.  All rights reserved.          *
  6 ;                                                                              *
  7 ;    This software and any accompanying information is for suggestion only.    *
  8 ;    It shall not be deemed to modify Microchip?s standard warranty for its    *
  9 ;    products.  It is your responsibility to ensure that this software meets   *
 10 ;    your requirements.                                                        *
 11 ;                                                                              *
 12 ;    SOFTWARE IS PROVIDED "AS IS".  MICROCHIP AND ITS LICENSORS EXPRESSLY      *
 13 ;    DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING  *
 14 ;    BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS    *
 15 ;    FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL          *
 16 ;    MICROCHIP OR ITS LICENSORS BE LIABLE FOR ANY INCIDENTAL, SPECIAL,         *
 17 ;    INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO     *
 18 ;    YOUR EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR    *
 19 ;    SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY   *
 20 ;    DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER      *
 21 ;    SIMILAR COSTS.                                                            *
 22 ;                                                                              *
 23 ;    To the fullest extend allowed by law, Microchip and its licensors         *
 24 ;    liability shall not exceed the amount of fee, if any, that you have paid  *
 25 ;    directly to Microchip to use this software.                               *
 26 ;                                                                              *
 27 ;    MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF    *
 28 ;    THESE TERMS.                                                              *
 29 ;                                                                              *
 30 ;*******************************************************************************
 31 ;                                                                              *
 32 ;    Filename:                                                                 *
 33 ;    Date:                                                                     *
 34 ;    File Version:                                                             *
 35 ;    Author:                                                                   *
 36 ;    Company:                                                                  *
 37 ;    Description:                                                              *
 38 ;                                                                              *
 39 ;*******************************************************************************
 40 ;                                                                              *
 41 ;    Notes: In the MPLAB X Help, refer to the MPASM Assembler documentation    *
 42 ;    for information on assembly instructions.                                 *
 43 ;                                                                              *
 44 ;*******************************************************************************
 45 ;                                                                              *
 46 ;    Known Issues: This template is designed for relocatable code.  As such,   *
 47 ;    build errors such as "Directive only allowed when generating an object    *
 48 ;    file" will result when the 'Build in Absolute Mode' checkbox is selected  *
 49 ;    in the project properties.  Designing code in absolute mode is            *
 50 ;    antiquated - use relocatable mode.                                        *
 51 ;                                                                              *
 52 ;*******************************************************************************
 53 ;                                                                              *
 54 ;    Revision History:                                                         *
 55 ;                                                                              *
 56 ;*******************************************************************************
 57 
 58 
 59 
 60 ;*******************************************************************************
 61 ; Processor Inclusion
 62 ;
 63 ; TODO Step #1 Open the task list under Window > Tasks.  Include your
 64 ; device .inc file - e.g. #include <device_name>.inc.  Available
 65 ; include files are in C:\Program Files\Microchip\MPLABX\mpasmx
 66 ; assuming the default installation path for MPLAB X.  You may manually find
 67 ; the appropriate include file for your device here and include it, or
 68 ; simply copy the include generated by the configuration bits
 69 ; generator (see Step #2).
 70 ;
 71 ;*******************************************************************************
 72 
 73 ; TODO INSERT INCLUDE CODE HERE
 74 
 75 ;*******************************************************************************
 76 ;
 77 ; TODO Step #2 - Configuration Word Setup
 78 ;
 79 ; The 'CONFIG' directive is used to embed the configuration word within the
 80 ; .asm file. MPLAB X requires users to embed their configuration words
 81 ; into source code.  See the device datasheet for additional information
 82 ; on configuration word settings.  Device configuration bits descriptions
 83 ; are in C:\Program Files\Microchip\MPLABX\mpasmx\P<device_name>.inc
 84 ; (may change depending on your MPLAB X installation directory).
 85 ;
 86 ; MPLAB X has a feature which generates configuration bits source code.  Go to
 87 ; Window > PIC Memory Views > Configuration Bits.  Configure each field as
 88 ; needed and select 'Generate Source Code to Output'.  The resulting code which
 89 ; appears in the 'Output Window' > 'Config Bits Source' tab may be copied
 90 ; below.
 91 ;
 92 ;*******************************************************************************
 93 
 94 
 95 #include "p16f877a.inc"
 96 
 97 ; CONFIG
 98 ; __config 0xFFFE
 99  __CONFIG _FOSC_HS & _WDTE_ON & _PWRTE_OFF & _BOREN_ON & _LVP_ON & _CPD_OFF & _WRT_OFF & _CP_OFF
100 
101     ERRORLEVEL   -302
102 
103 ;*******************************************************************************
104 ;
105 ; TODO Step #3 - Variable Definitions
106 ;
107 ; Refer to datasheet for available data memory (RAM) organization assuming
108 ; relocatible code organization (which is an option in project
109 ; properties > mpasm (Global Options)).  Absolute mode generally should
110 ; be used sparingly.
111 ;
112 ; Example of using GPR Uninitialized Data
113 ;
114 ;   GPR_VAR        UDATA
115 ;   MYVAR1         RES        1      ; User variable linker places
116 ;   MYVAR2         RES        1      ; User variable linker places
117 ;   MYVAR3         RES        1      ; User variable linker places
118 ;
119 ;   ; Example of using Access Uninitialized Data Section (when available)
120 ;   ; The variables for the context saving in the device datasheet may need
121 ;   ; memory reserved here.
122 ;   INT_VAR        UDATA_ACS
123 ;   W_TEMP         RES        1      ; w register for context saving (ACCESS)
124 ;   STATUS_TEMP    RES        1      ; status used for context saving
125 ;   BSR_TEMP       RES        1      ; bank select used for ISR context saving
126 ;
127 ;*******************************************************************************
128 
129 ;Registerzuweisungen
130  
131 REG_1 EQU 0x20
132  
133 REG_2 EQU 0x21
134 
135 REG_3 EQU 0x22
136 
137 ; Macrodefinitionen
138  
139 bank0   macro
140             bcf STATUS,RP0
141             endm
142 
143 bank1   macro
144             bsf STATUS,RP0
145             endm
146 ;*******************************************************************************
147 ; Reset Vector
148 ;*******************************************************************************
149 
150 RES_VECT  CODE    0x0000            ; processor reset vector
151     GOTO    START                   ; go to beginning of program
152 
153 ;*******************************************************************************
154 ; TODO Step #4 - Interrupt Service Routines
155 ;
156 ; There are a few different ways to structure interrupt routines in the 8
157 ; bit device families.  On PIC18's the high priority and low priority
158 ; interrupts are located at 0x0008 and 0x0018, respectively.  On PIC16's and
159 ; lower the interrupt is at 0x0004.  Between device families there is subtle
160 ; variation in the both the hardware supporting the ISR (for restoring
161 ; interrupt context) as well as the software used to restore the context
162 ; (without corrupting the STATUS bits).
163 ;
164 ; General formats are shown below in relocatible format.
165 ;
166 ;------------------------------PIC16's and below--------------------------------
167 ;
168 ; ISR       CODE    0x0004           ; interrupt vector location
169 ;
170 ;     <Search the device datasheet for 'context' and copy interrupt
171 ;     context saving code here.  Older devices need context saving code,
172 ;     but newer devices like the 16F#### don't need context saving code.>
173 ;
174 ;     RETFIE
175 ;
176 ;----------------------------------PIC18's--------------------------------------
177 ;
178 ; ISRHV     CODE    0x0008
179 ;     GOTO    HIGH_ISR
180 ; ISRLV     CODE    0x0018
181 ;     GOTO    LOW_ISR
182 ;
183 ; ISRH      CODE                     ; let linker place high ISR routine
184 ; HIGH_ISR
185 ;     <Insert High Priority ISR Here - no SW context saving>
186 ;     RETFIE  FAST
187 ;
188 ; ISRL      CODE                     ; let linker place low ISR routine
189 ; LOW_ISR
190 ;       <Search the device datasheet for 'context' and copy interrupt
191 ;       context saving code here>
192 ;     RETFIE
193 ;
194 ;*******************************************************************************
195 ;Definitionen
196     ; Ports umbenennen
197 #define GPIO    PORTD                  
198 #define TRISIO  TRISD
199     ; Portpins benennen    
200 #define LED_0   GPIO,0
201 #define LED_1   GPIO,1                
202 #define LED_2   GPIO,2
203 #define LED_3   GPIO,3
204 #define LED_4   GPIO,4
205 #define LED_5   GPIO,5
206 #define LED_6   GPIO,6
207 #define LED_7   GPIO,7
208 
209 ;*******************************************************************************
210 ; MAIN PROGRAM
211 ;*******************************************************************************
212 
213 MAIN_PROG CODE                  ; let linker place main program
214 
215 START
216 
217     ; TODO Step #5 - Insert Your Program Here
218         call INIT_IO  
219 ;LED einschalten        
220 blink   bsf  LED_0                      ; set LED_0
221 ;***********************************************************         
222 ;Warteschleife 1
223         clrf REG_1
224         clrf REG_2
225 loop1   decfsz REG_1
226         goto loop1
227         decfsz REG_2
228         goto loop1
229         clrf REG_1
230         clrf REG_2
231 ;LED ausschalten
232         bcf LED_0                       ;clear LED_0
233 ;Warteschleife 2
234         clrf REG_1
235         clrf REG_2
236 loop2   decfsz REG_1
237         goto loop1
238         decfsz REG_2
239         goto loop2
240 ;***********************        
241         goto blink                      ; loop forever
242                 
243  
244 
245 
246 ;****************************************************************************
247 INIT_IO clrf    GPIO    ; lösche Port (setze alle Ausgänge auf "0")
248         bank1           ; auf Bank1 umschalten
249         movlw   0x00    ; definiere Portpins  als Ausgänge
250         movwf   TRISIO  ; schreibe in TRIS Register
251         bank0           ; auf Bank0 umschalten
252         return          ; springe zurück 
253  
254       END               ; Ende Programm
255