;; ;; isa0.ASM ;; ;; RomaNets Software ;; ;; ;; Board_#8 (28 pins) ( Veroboard) PIC16F873 ;; 20MHz _HS_Generator ;; ;; Using only 8 bit ADC (MSB) ;; ;; ;; Syncronous serial protocal ;; RA2 - data ;; RA3 - sync _- ;; ;; ;; RB0 - LCDData ;; RB1 - LCDSync _- ;; RB2 - Podlozhka control LCDPCtrl ;; ;; We have two variants to display contents of the byte: ;; 1) call ConvertByte2ThreeDecDigits - 0..255 ;; 2) call ConvertByte2TwoHexDigits - 0..FF ;LIST P=16F870, R=DEC ;INCLUDE "C:\Program Files\MPLAB IDE\MCHIP_Tools\p16f870.inc" LIST P=16F873, R=DEC INCLUDE "C:\Program Files\MPLAB IDE\MCHIP_Tools\p16f873.inc" ;; PORTA DData EQU 0x02 ; do not used in this ex DSync EQU 0x03 DLAY EQU 10 ;; PORTB LCDData EQU 0x00 LCDSync EQU 0x01 LCDPCtrl EQU 0x02 ; Register Usage CBLOCK 0x20 _w _status Count Count2 Count3 digit1 digit2 digit3 digit4 digitemp count1 ;_LCD_number ;AD_TWO_MSBits ;_LCD_digit2 ;cnt_ChangeDigit LCD_state LCDLoader_count LCDLoader_digitemp bin hundreds tens_and_ones tmp_hex ;skip_interrupt_cnt ENDC ;_RC_OSC ;_XT_OSC PAGE __CONFIG _CP_OFF & _DEBUG_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF &_HS_OSC & _PWRTE_ON & _WDT_OFF ; Note that the WatchDog Timer is OFF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Code org 0 goto Init org 4 ;========================================================== ; Interrupt handler ;========================================================== movwf _w movf STATUS, w movwf _status bcf INTCON, T0IF movf _status, w movwf STATUS swapf _w, f swapf _w, w retfie ;; ;; End of interrupt handler ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Init ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bsf STATUS, RP0 ; bank 1 ; movlw 0xFF ; init RA0-RA5 for input ; movwf TRISA & 0x7F movlw 0x00 ; init RB0-RB7 for output movwf TRISB & 0x7F movlw 0x00 ; init RC0-RC7 for output movwf TRISC & 0x7F ;ADC movlw 0x02 ; analog input on AN1/AN0, ADFM - left justified ;movlw 0x82 ; analog input on AN1/AN0, ADFM - right justified movwf ADCON1 & 0x7F ; 0xD4 - prscaler 0111 1/256 ; 1,843,200 Hz /4 /256 (=1800))/32(0xD4) = 56.25 Hz 28.125 Hz for LCD ; 0xD3 - prscaler 0111 1/256 ; 1,843,200 Hz /4 /256 (=1800))/16(0xD3) =112.5 Hz 56.25 Hz for LCD ; 0xD7 - prscaler 0111 1/256 ; 20,000,000 Hz /4 /256 /256(0xD7) = 76 Hz 38 Hz for LCD ; 0xD3 - prscaler 0011 1/16 ; 1,000,000 Hz /4 /256 /16(0xD3) = 61 Hz 30 Hz for LCD ;20,000,000 Hz /4 /256 /16(0xD3) = 1220 Hz 610 Hz for LCD ; 0xD2 - prscaler 0010 1/8 ; 1,000,000 Hz /4 /256 /8(0xD2) = 122 Hz ; 0xD1 - prscaler 0001 1/4 ; 1,000,000 Hz /4 /256 /4(0xD1) = 244 Hz ; 0xD0 - prscaler 0000 1/2 ; 1,000,000 Hz /4 /256 /2(0xD0) = 488 Hz movlw 0xD7 ; use timer, no RBPU, edge don't care movwf OPTION_REG & 0x7F ; prescaler to TMR0(not WDT) LS_3_Bits bcf STATUS, RP0 ; bank 0 ; clrf TMR0 ; movlw 0xA0 ; enable TMRO ; movwf INTCON clrf LCD_state ;movlw 2 ;movwf skip_interrupt_cnt movlw 0xFF movwf PORTB movlw 0xFF ; light off all LEDs movwf PORTC ;////////////////////////////////////////////////////////// MainCycle ;////////////////////////////////////////////////////////// ;; Calculation of delay: 20,000,000 / 4 / 2631720 = 3.8 Hz ;; TEST BEGIN ;; TEST END ; ;movlw 0xFF ; 256 * 1280 + 1280 = 328960 ; movlw 0x1 ; movwf Count2 ;OuterDelayCycle ; decfsz Count2, f ; goto InnerDelayCycle ; goto CodeAfterDelay ;InnerDelayCycle ; ;movlw 0xFF ; 256 * (1+1+1+2) = 1280 ; movlw 0x1 ; movwf Count1 ; decfsz Count1, f ; goto $-1 ; goto OuterDelayCycle CodeAfterDelay movlw 0xFF xorwf PORTC, f ;movlw 0x81 ; ADC enable Fosc/32 ?kHz movlw 0xC1 ; ADC enable inner 250 kHz ;movlw 0x01 ; ADC enable Fosc/2 movwf ADCON0 movlw 25 ; delay == 20mks ;movlw 3 ; delay == 20mks with Fosc = 1.8432 MHz ;movlw 2 ; delay == ?mks with Fosc = 1.8432 MHz addlw 0xFF ; 1 ; 4*25 * [(1/(20,000,000/4))==0.2mks] = 20 ; 4*3 * [(1/( 1,843,200/4))==2.17mks] = 26 ; 4*2 * [(1/( 1,843,200/4))==2.17mks] = 26 btfss STATUS, Z ; 1 ; goto $-2 ; 2 ; bsf ADCON0, GO btfsc ADCON0, GO goto $-1 movf ADRESH, w movwf PORTB goto MainCycle end