[Menu]>[Circuits Gallery]>[Remote display]>[Improvement]
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | ;******************************************************** ; ; Remote display ; (Display) ; Divice : PIC16F873 ; Author : Seiichi Inoue ;******************************************************** list p=pic16f873 include p16f873.inc __config _hs_osc & _wdt_off & _pwrte_on & _lvp_off errorlevel -302 ;Suppress bank warning ;**************** Label Definition ******************** cblock h'20' data_h ;100th digit data data_t ;10th digit data data_u ;1st digit data cdisp_p ;Category LED position ddisp_p ;Digit LED position rcv_p ;Receive data position r_category ;Category data save area data_rcv ;Data received flag endc ;**************** Program Start *********************** org 0 ;Reset Vector goto init org 4 ;Interrupt Vector goto int ;**************** Initial Process ********************* init ;*** Port mode initializing bsf status,rp0 ;Change to Bank1 movlw b'00000110' ;RA port to digital mode movwf adcon1 ;Set ADCON1 register clrf trisa ;Set RA to output mode clrf trisb ;Set RB to output mode movlw b'10000000' ;RC7 input, other output movwf trisc ;Set TRISC register ;*** LED scan interval initializing (Timer0 = 2ms) movlw b'10000010' ;PBPU=off,PSA=0,PS=1:8 movwf option_reg ;Set OPTION_REG register bcf status,rp0 ;Change to Bank0 movlw d'6' ;(256-6)x8=2000usec movwf tmr0 ;Set TMR0 register ;*** Port initializing clrf porta ;Clear porta ;*** Work area initializing clrf data_h ;Clear 100th LED data clrf data_t ;Clear 10th LED data clrf data_u ;Clear 1st LED data clrf cdisp_p ;Clear Category position clrf ddisp_p ;Clear 7 segment position clrf rcv_p ;Clear receive position clrf r_category ;Clear Category save area movlw d'1' ;Set Data received flag movwf data_rcv ;Set flag ;*** USART control bsf status,rp0 ;Change to Bank1 movlw d'25' ;Speed = 9600bps movwf spbrg ;Set SPBRG register bcf txsta,sync ;Set Async mode bsf txsta,brgh ;Set BRGH(High-speed) bsf pie1,rcie ;Set RX interruption bcf status,rp0 ;Change to Bank0 bsf rcsta,spen ;Set Serial-port bsf rcsta,cren ;Set Receive enable ;*** Interruption control movlw b'11100000' ;GIE,PEIE,T0IE = ON movwf intcon ;Set INTCON register wait goto $ ;wait ;*************** Interruption Process ***************** int btfsc intcon,t0if ;Check TMR0 goto led ;TMR0 time-out btfsc pir1,rcif ;Check RX buffer goto rcv_data ;Data receive process ;******** Illegal interruption (For debugging) ******** illegal movlw b'01001111' ;Set 7segment pattern "E" movwf portb ;Write LED data movlw b'00000100' ;Set 1st digit select movwf porta ;Write LED select data goto $ ;Stop ;************ END of Interruption Process ************** int_end retfie ;**************** LED control Process ***************** led bcf intcon,t0if ;Clear T0IF movlw d'6' ;Set Time value (2msec) movwf tmr0 ;Write TMR0 register ;**** Category display control movfw cdisp_p ;Read category position movwf portc ;Write category position incf cdisp_p,f ;Increment position movlw d'11' ;Set check data subwf cdisp_p,w ;Check category position btfsc status,c ;Position over ? clrf cdisp_p ;Clear category position ;**** 7 segment display control led1 movfw data_rcv ;Read Data recived flag btfsc status,z ;Received ? goto led10 ;No. Not received movfw ddisp_p ;Read 7 segment position btfss status,z ;Position = LED1 data ? goto led2 ;No. movfw data_h ;Read 100th digit data movwf portb ;Write LED control data goto led_cont ;Jump to position change led2 movlw d'1' ;Set check data subwf ddisp_p,w ;Check data btfss status,z ;Position = LED1 ON ? goto led3 ;No. movfw porta ;Read RA port andlw b'00111000' ;Keep category sel data iorlw b'00000001' ;Set LED1 control data movwf porta ;Write LED select data goto led_cont ;Jump to position change led3 movlw d'2' ;Set check data subwf ddisp_p,w ;Check data btfss status,z ;Position = LED1 OFF ? goto led4 ;No. movfw porta ;Read RA port andlw b'00111000' ;Keep category sel data iorlw b'00000000' ;Set LED1 control data movwf porta ;Write LED select data goto led_cont ;Jump to position change led4 movlw d'3' ;Set check data subwf ddisp_p,w ;Check data btfss status,z ;Position = LED2 data ? goto led5 ;No. movfw data_t ;Read 10th digit data movwf portb ;Write LED control data goto led_cont ;Jump to position change led5 movlw d'4' ;Set check data subwf ddisp_p,w ;Check data btfss status,z ;Position = LED2 ON ? goto led6 ;No. movfw porta ;Read RA port andlw b'00111000' ;Keep category sel data iorlw b'00000010' ;Set LED2 control data movwf porta ;Write LED select data goto led_cont ;Jump to position change led6 movlw d'5' ;Set check data subwf ddisp_p,w ;Check data btfss status,z ;Position = LED2 OFF ? goto led7 ;No. movfw porta ;Read RA port andlw b'00111000' ;Keep category sel data iorlw b'00000000' ;Set LED2 control data movwf porta ;Write LED select data goto led_cont ;Jump to position change led7 movlw d'6' ;Set check data subwf ddisp_p,w ;Check data btfss status,z ;Position = LED3 data ? goto led8 ;No. movfw data_u ;Read 1st digit data movwf portb ;Write LED control data goto led_cont ;Jump to position change led8 movlw d'7' ;Set check data subwf ddisp_p,w ;Check data btfss status,z ;Position = LED3 ON ? goto led9 ;No. movfw porta ;Read RA port andlw b'00111000' ;Keep category sel data iorlw b'00000100' ;Set LED3 control data movwf porta ;Write LED select data goto led_cont ;Jump to position change led9 movlw d'8' ;Set check data subwf ddisp_p,w ;Check data btfss status,z ;Position = LED3 OFF ? goto led10 ;No. movfw porta ;Read RA port andlw b'00111000' ;Keep category sel data iorlw b'00000000' ;Set LED3 control data movwf porta ;Write LED select data led_cont incf ddisp_p,f ;Increment position movlw d'9' ;Set check data subwf ddisp_p,w ;Check 7 sebment position btfsc status,c ;Position over ? goto led10 ;Yes. Over goto int_end ;Jump to END of interrupt led10 clrf data_rcv ;Clear data received flag clrf ddisp_p ;Clear 7 segment position goto int_end ;Jump to END of interrupt ;*************** Data receive Process ***************** rcv_data btfss rcsta,oerr ;Overrun error ? goto rcv1 ;No. Normal rcv_reset bcf rcsta,cren ;Clear receive enable bit bsf rcsta,cren ;Set receive enable bit goto data_clear ;Jump to data clear rcv1 btfss rcsta,ferr ;Frame error ? goto rcv2 ;No. Normal data_clear movfw porta ;Read porta andlw b'00000111' ;Clear category data movwf porta ;Write porta clrf data_h ;Clear 100th data clrf data_t ;Clear 10th data clrf data_u ;Clear 1st data clrf rcv_p ;Clear receive position goto int_end ;Jump to END of interrupt rcv2 movfw rcv_p ;Read receive position btfss status,z ;Position = start ? goto rcv3 ;No. Next movlw b'10000000' ;Set check data subwf rcreg,w ;Check start data btfss status,z ;Start data ? goto int_end ;Jump to END of interrupt movfw rcreg ;Read received data incf rcv_p,f ;Set receive position = 1 goto int_end ;Jump to END of interrupt rcv3 movlw d'1' ;Set check data subwf rcv_p,w ;Check receive position btfss status,z ;Position = category ? goto rcv10 ;No. Next btfss rcreg,6 ;Check 'SEI' bit goto rcv4 ;'SEI' = 0 bcf r_category,3 ;Set 'SEI' 0 goto rcv5 ;Next rcv4 bsf r_category,3 ;Set 'SEI' 1 rcv5 btfss rcreg,5 ;Check 'TEN' bit goto rcv6 ;'TEN' = 0 bcf r_category,4 ;Set 'TEN' 0 goto rcv7 ;Next rcv6 bsf r_category,4 ;Set 'TEN' 1 rcv7 btfss rcreg,4 ;Check 'PU' bit goto rcv8 ;'PU' = 0 bcf r_category,5 ;Set 'PU' 0 goto rcv9 ;Next rcv8 bsf r_category,5 ;Set 'PU' 1 rcv9 movfw porta ;Read porta andlw b'00000111' ;Clear category data iorwf r_category,w ;Set category data movwf porta ;Write porta incf rcv_p,f ;Set receive position = 2 goto int_end ;Jump to END of interrupt rcv10 movlw d'2' ;Set check data subwf rcv_p,w ;Check receive position btfss status,z ;Position = 100th ? goto rcv11 ;No. Next movfw rcreg ;Read received data xorlw b'11111111' ;Reverse 0 and 1 movwf data_h ;Write 100th data incf rcv_p,f ;Set receive position = 3 goto int_end ;Jump to END of interrupt rcv11 movlw d'3' ;Set check data subwf rcv_p,w ;Check receive position btfss status,z ;Position = 10th ? goto rcv12 ;No. Next movfw rcreg ;Read received data xorlw b'11111111' ;Reverse 0 and 1 movwf data_t ;Write 10th data incf rcv_p,f ;Set receive position = 4 goto int_end ;Jump to END of interrupt rcv12 movlw d'4' ;Set check data subwf rcv_p,w ;Check receive position btfss status,z ;Position = 1st ? goto rcv_reset ;No. Error movfw rcreg ;Read received data xorlw b'11111111' ;Reverse 0 and 1 movwf data_u ;Write 1st data clrf rcv_p ;Clear receive position incf data_rcv,f ;Set data received flag goto int_end ;Jump to END of interrupt end |
r_disp2_source.zip r_disp2_hex.zip |