hallo.ASM


1
;**********************************************************************
2
;   This file is a basic code template for assembly code generation   *
3
;   on the PIC16F876. This file contains the basic code               *
4
;   building blocks to build upon.                                    *  
5
;                                                                     *
6
;   Refer to the MPASM User's Guide for additional information on     *
7
;   features of the assembler (Document DS33014).                     *
8
;                                                                     *
9
;   Refer to the respective PIC data sheet for additional             *
10
;   information on the instruction set.                               *
11
;                                                                     *
12
;**********************************************************************
13
;                                                                     *
14
;    Filename:      xxx.asm                                           *
15
;    Date:                                                            *
16
;    File Version:                                                    *
17
;                                                                     *
18
;    Author:                                                          *
19
;    Company:                                                         *
20
;                                                                     * 
21
;                                                                     *
22
;**********************************************************************
23
;                                                                     *
24
;    Files Required: P16F876.INC                                      *
25
;                                                                     *
26
;**********************************************************************
27
;                                                                     *
28
;    Notes:                                                           *
29
;                                                                     *
30
;**********************************************************************
31
32
33
  list      p=16f876            ; list directive to define processor
34
  #include <p16f876.inc>        ; processor specific variable definitions
35
  
36
  __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _LP_OSC & _WRT_ENABLE_ON & _LVP_OFF & _DEBUG_ON & _CPD_OFF 
37
38
; '__CONFIG' directive is used to embed configuration data within .asm file.
39
; The lables following the directive are located in the respective .inc file.
40
; See respective data sheet for additional information on configuration word.
41
42
43
44
45
46
47
;***** VARIABLE DEFINITIONS
48
w_temp        EQU     0x7E        ; variable used for context saving 
49
status_temp   EQU     0x7F        ; variable used for context saving
50
loops      EQU    0x21
51
loop_2ms    EQU    0x22
52
lcddata      EQU    0x23
53
54
  #define          E    PORTA,0  
55
    #define          RW    PORTA,1
56
    #define          RS    PORTA,2
57
  #define          BU    PORTB,7
58
59
60
61
62
63
64
65
;**********************************************************************
66
    ORG     0x000             ; processor reset vector
67
    clrf    PCLATH            ; ensure page bits are cleared
68
      goto    main              ; go to beginning of program
69
70
71
    ORG     0x004             ; interrupt vector location
72
    movwf   w_temp            ; save off current W register contents
73
    movf  STATUS,w          ; move status register into W register
74
    movwf  status_temp       ; save off contents of STATUS register
75
76
77
; isr code can go here or be located as a call subroutine elsewhere
78
79
80
    movf    status_temp,w     ; retrieve copy of STATUS register
81
    movwf  STATUS            ; restore pre-isr STATUS register contents
82
    swapf   w_temp,f
83
    swapf   w_temp,w          ; restore pre-isr W register contents
84
    retfie                    ; return from interrupt
85
86
wrinstr
87
88
    ;call rbusy
89
  bcf  RS
90
  bcf  RW
91
  movf lcddata,w
92
  movwf  PORTB
93
  bsf  E
94
  nop
95
  bcf  E
96
  return
97
98
wrdata
99
100
    ;call rbusy
101
  bsf  RS
102
  bcf  RW
103
  movf lcddata,w
104
  movwf  PORTB
105
  bsf  E
106
  nop
107
  bcf  E
108
  return
109
110
WAIT
111
top
112
        nop
113
        nop
114
      nop
115
        nop
116
        nop
117
        decfsz  loops, F       ; outer loops complete?
118
        goto    top            ; no, go again
119
        retlw   0              ; yes, return from WAIT
120
121
WAIT_2ms
122
123
    movlw d'8'
124
        movwf loop_2ms
125
top1
126
        decfsz loop_2ms,F
127
    goto top1
128
    retlw   0
129
130
131
132
main
133
134
; remaining code goes here
135
136
    banksel PORTA
137
       
138
    movlw  d'250'
139
  movwf  loops
140
  call    WAIT
141
142
    banksel TRISA
143
  movlw b'00000000'       ;PortA output
144
  movwf  TRISA
145
146
  movlw b'00000000'       ;PortB output
147
  movwf  TRISB
148
149
    banksel PORTA
150
  
151
152
    movlw b'00110000'    ;Funktion set
153
    movwf lcddata
154
  call wrinstr
155
156
  movlw b'00001100'   ;display on
157
  movwf lcddata
158
  call wrinstr
159
    
160
161
    movlw b'00000001'    ;Display clear
162
    movwf lcddata
163
  call wrinstr
164
    call WAIT_2ms
165
166
    movlw b'00000110'    ;Entry mode set
167
    movwf lcddata
168
  call wrinstr
169
170
  movlw b'01001000'  ;H
171
  movwf lcddata
172
  call wrdata
173
    
174
175
  movlw b'01000001'  ;A
176
  movwf lcddata
177
  call wrdata
178
    
179
180
  movlw b'01001100'  ;L
181
  movwf lcddata
182
  call wrdata
183
    
184
185
  movlw b'01001100'  ;L
186
  movwf lcddata
187
  call wrdata
188
    
189
190
  movlw b'01001111'  ;O
191
  movwf lcddata
192
  call wrdata
193
    nop
194
195
prog
196
goto prog
197
198
199
200
201
;rbusy
202
;    bcf BU
203
;    banksel TRISB  
204
;  bsf TRISB,7
205
;  bcf RS
206
;  bsf RW
207
;bloop  btfsc BU
208
;  goto bloop
209
;  bcf TRISB,7
210
;  banksel PORTB
211
;  return
212
213
214
215
216
217
218
  END                       ; directive 'end of program'