Light tight cover Scintillator Photocathode Dynode V2 V4 Incident radiation V1 V3 photo electron Dynode
Photocathode Dynode Focus 1 Anode cs cs cs Rd Rd Rd Rd Resistor voltage divider +HV From PM tube 증폭기 (AMP) Pulse Height Analysis TTL Pulse 출력 고전압발생기 VH control VL control HV control 조절단자
+5V Q1 A1244 I1 C16 C19 0.1u 0.1u D5 R17 200 R25 120k R26 2k - U4B 1G + - U6A HV control 1M + R19 4.7M C18 R18 C17 1n 4.7M GP0230 1n D12 D11 D10 D9 D8 PM tube R18 500k C21 47u 10n R23 100k R21 220 I2 Q2 2N3904 0.22u C26 C25 10n C24 10n C23 10n
High Voltage out R25 120k 1G 1M R14 R15 - U4B + feed back voltage (1/1001) of Vout R26 2k - + U6A R23 100k Blocking OSC HV Control 0~2.5V HV control Control voltage 0~2.5V 61 + - V1 Blocking OSC V2 non linear 60 1001 VH
2000 1500 1000 500 0 0 0.5 1 1.5 2
+5V U1A 4538 R10 R5 2.5V - + A3 R7 R8 1.2V 1.2V 1.2V R12 Vp + U3A - VL + U3B - VH R13 R12 +5V +5V RC CX +T -T U1B RC CX +T -T Q R Q 4538 Q R Q PHA out U1A 출력 Vp VL<Vp<VH Vp<VL Vp>VH
LCD control circuit LCD Display Control PC (1) channel setting Counting interval setting (2) saving counting data GPIB Microcontroller PIC16F877 다채널계수장치 24 counters 24 radiation detecting circuits 24 gamma ray sensors (detector) Random access memory
D0-D7 D0-D7 CLK0 G0 OUT0 Pulse input1 RD WR A0 A1 CNT0 /RD /WR A0 A1 /CS CLK1 G1 OUT1 CLK2 G2 OUT2 Pulse input2 Pulse input3 A2 A3 A4 8254 Vcc 1 2 3 6 4 5 74LS138 15 14 13 12 11 10 9 7 CNT0 CNT1 CNT2 CNT3 CNT4 CNT5 CNT6 CNT7 RD WR A0 A1 CNT1 D0-D7 /RD /WR A0 A1 /CS CLK0 G0 OUT0 CLK1 G1 OUT1 CLK2 G2 OUT2 Pulse input4 Pulse input5 Pulse input6 D0-D7 CLK0 G0 OUT0 Pulse input22 RD WR A0 A1 CNT7 /RD /WR A0 A1 /CS CLK1 G1 OUT1 CLK2 G2 OUT2 Pulse input23 Pulse input24
Counter Latch Command Read operation Counter value ->DATA BUS BUFFER(8254) DATA BUS BUFFER(8254) -> MICOM Previous count value - incoming count value-> count value complimnet count value ASCII conversion count value Transmit ASCII data
D8 REN SC NDAC NRFD DAV EOI ATN SRQ Nat9914 75ALS160 D7 D6 D5 D4 D3 D2 D1 TE PE TE IFC DIO8 DIO7 DIO6 DIO5 DIO4 DIO3 DIO2 DIO1 REN IFC NDAC NRFD DAV EOI ATN SRQ 684000 RS0 RS1 RS2 A0 A1 A2 74ALS573 A8-A15 74ALS573 A0-A7 684000 A0-A15 D0-D7 RB6 RB7 RAM1 RAM2 WR RD RD WR RD WR RAM1 RAM2 RB2 RB3 RE0 RE1 RD WR INT RST CLOCK INT RB0/INT CS CS RE2 DBIN WE INT RESET CLK CE 75ALS162 TE PIC16F877
CPU bus control address 75ALS160 D0 -D7 decoder PIC16F877 data NAT9914 GPIB RB0/INT interrupt 75ALS162
GPIB interrupt handler not end of message byte in input a byte last byte of message interpret command execute command MOVLW AUXMR ; SWITCH TO 9914 MODE ; AUXMR =5 MOVLW 0X15 ; sw9914=0x15) ;------------------ MOVLW AUXCR ; page in accessory registor ; auxcr =3 MOVLW 0X1C ; OX1C = chip reset, clear page in registor ; clear status registor CLRF ISR0 CLRF ISR1 ;--------set clock speed system clock speed를설정한다, nat9914의 18번핀의 clock MOVLW AUXCR ; 에인가되는클럭을기준으로설정한다. page in accessory registor ; auxcr =3 MOVLW 0X9F
MOVLW ACCR MOVLW B'00100100' ; ACCR=2 ; ICR 4Mhz icr MOVLW AUXCR ; clear page in resistor MOVLW 0X9C ;---------------- T1 delay MOVLW AUXCR ; MOVLW 0X97 ; set very short T1 delay (~vstdl) ;---------------- enable interrupt INTERUPT MASK 0 SET MOVLW IMR0 ; MOVLW B'00100000' ; Byte IN(BI) 만인터럽트허용 ;----------------- INTERUPT MASK 1 SET MOVLW IMR1 MOVLW B'10001000' ;----------------- page in interupt mask resistor2 MOVLW AUXCR MOVLW 0X1E ;(piimr2) MOVLW IMR2 MOVLW B'10000000' ; clear global interupt bit MOVLW AUXCR ; CLEAR PAGE IN REGISTOR MOVLW 0X9C ;------------- Line feed 문자를 end of string으로사용 MOVLW AUXCR ; auxcr=3 MOVLW 0X9E ; (pieosr) page in end of string resistor MOVLW EOSR ; esor=2 MOVLW NEWLINE ; ; MOVLW AUXCR ; auxcr=3 MOVLW 0X9C ; clear page in resistor ;-------------- MOVLW AUXCR ; page in accessory registor MOVLW 0X9F ; MOVLW ACCR
MOVLW B'10001100' ; accra MOVLW AUXCR ; clear page in resistor MOVLW 0X9C ; c_piaccr ;------------------- set inv active low MOVLW AUXCR ; page in accessory registor ; auxcr =3 MOVLW 0X9F MOVLW ACCR ; MOVLW B'10100000' ; ICR 4Mhz MOVLW AUXCR ; clear page in resistor MOVLW 0X9C ;------------ GPIB device address 설정 MOVLW ADR ; ADR=4 MOVLW 0X02 ; ;------------- enable the device to receive data and command MOVLW AUXCR MOVLW 0X00 ; (c_nswrst) clear software reset RETURN
MOVLW SPSR ; Serial Poll Status Register - 데이터전송을위한준비시작 ; 첫번재단계로현재 nat9914의 spsr상태를 check CALL GPIB_RD ; 하여 SPSR_BYTE에저장 MOVF GPIB_DAT,W ; SPSR =5 MOVWF SPSR_BYTE ; SPMR =5 MOVLW SPMR ; Serial Poll Mode 를통하여데이터전송준비가되엇음을
; 알린다. RSV 대신 RSV2 를사용하여전송하는 routine 이다 BCF SPSR_BYTE,6 ; clear request service bit(rsv) BSF SPSR_BYTE,4 ; SET Message Available bit MOVF SPSR_BYTE,W MOVLW AUXCR ; AUXCR =3 ; MOVLW 0X98 ; Set Request Service bit 2 (RSV2) CALL WAIT_BO ; 데이터전송준비끝나고 BO가 SET될때까지기다린다. MOVLW CDOR ; 데이터를 CDOR register에전송시작 ; CDOR=7 MOVLW 'K' ; K송신 CALL WAIT_BO MOVLW CDOR MOVLW 'T' ; T 송신 CALL WAIT_BO MOVLW CDOR MOVLW 'G' ; G 송신 CALL WAIT_BO MOVLW CDOR MOVLW '-' ; - 송신 CALL WAIT_BO MOVLW CDOR MOVLW 'D' ; D 송신
CALL WAIT_BO MOVLW CDOR MOVLW 'A' ; A 송신 CALL WAIT_BO MOVLW CDOR MOVLW 'Q' ; Q 송신 CALL WAIT_BO ; End of string송신 MOVLW CDOR ; Message의끝을알리기위해 line feed문자를송신한다. MOVLW 0X0A RETURN
Power On User Reguest Command Error Execution Error Device Dependent error Query Error Request Control Operation Complete 7 6 5 4 3 2 1 0 Standard Event Status Register *ESR? Logical OR & & Queue Not-Empty & & & & & & Standard Event Status Enable 7 6 5 4 3 2 1 0 Register *ESE<NRf> *ESE? Output Queue Ready by Serial Poll Service Request Generation 7 RQS 6 MSS ESB MAV 3 2 1 0 Status Byte Register Logical OR & & & & & & & 7 5 4 3 2 1 0 Ready by *STB? Service Request Enable Register *SRE<NRf> *SRE?
GPIB_INT ; nat9914 interupt subroutine BCF INTCON,INTF MOVLW ISR0 ; check interupt source ; ISR0 byte를가져와인터럽트의원인을확인한다 CALL GPIB_RD MOVF GPIB_DAT,W MOVWF ISR0_BYTE ; ISR0중 BI가 set이면 BYTE_IN 쪽으로점프 BTFSC BI ; GPIB interrupt 중 BI만설정해놓았음으로 GOTO BYTE_IN ; 사실상필요없는명령임 BYTE_IN ; gpib reading state MOVF FSR_IN,W MOVWF FSR MOVLW DIR CALL GPIB_RD MOVF GPIB_DAT,W MOVWF INDF INCF FSR_IN,F BCF BI ; BTFSS B_END ; B_END flag check하여 Message의끝인지여부를확인? GOTO INT_RET BSF BI_F BCF B_END MOVLW BUFFER MOVWF FSR_IN INTRET BYTE_OUT INTRET ; gpib writing state
Start initialize GPIB RECEIVING BUFFER FULL? yes interpret command PARSE END CHANNEL SET TIME SET SEND IDN? SEND TIMER1 ON READ INITIAL VALUE OF 8254 TIMER1 OVERFLOW yes COUNTER LATCH COMMAND READ DATA FROM 8254 SEND DATA TO PC via IEEE488 yes RECEIVING BUFFER FULL?
START Configure GPIB Send 'TMS0' by GPIB time interval setting Send 'CH:XX' by GPIB channel number setting Send 'SEND' by GPIB Start downloading data "END" received? END Get 97 byte at GPIB convert ASCII data to 24 array numbers 24 array numbers + old numbers=old numbers time interval plot XY graph data save? save data as ASCII
24 채널다중계수장치 GPIB 24 개 detector 24 개방사선계측기
PC Control Program (Labview) GPIB connection DAQ GPIB connection PCMCI CARD
;**************************************************** ; PROJECT NAME : 2003 KAERI ; PROGRAM NAME : P877 ; REVISED DATE : 2003.12 ; PROGRAM MODIFIED : jong ;**************************************************** ;---------------------------------------------------- ; INSTRUCTION SET ;---------------------------------------------------- ; f File Register ; w Working Register ; (f) Stored Data in File Register ; (w) Stored Data in Working Register ; d Destination (F=1, W=0) ; k Data (Coeficient) ; f.b Bit of F (or W) ; f.b1:b2 Between b1 Bit and b2 Bit of F (or W) ; TOS Top of Stack Address ; ADDLW k Add Literal of W, (W)+K->W ; ADDWF f,d Add W to F,(W)+(F)->d ; ANDLW k AND Literal and W, (W) AND K->W ; ANDWF f,d AND W with F, (W) AND (F)->d ; BCF f,b Bit Clear F, 0->F.b ; BSF f,b Bit Set F, 1->F.b ; BTFSC f,b Bit Test, Skip If Clear, Skip if F.b=0 ; BTFSS f,b Bit Test, Skip If Set, Skip if F.b=1 ; CALL k Subroutine Call ; CLRF f Clear F, 00H->F, 1->Z ; CLRW Clear W, 00H->W, 1->Z ; CLRWDT Clear WatchdogTimer,00H->WDT, 0->WDT ; COMF f,d Complement F, NOT(F)->d ; DECF f,d Decrement F, (F)-1 ->d ; DECFSZ f,d Dec. F Skip if Zero,(F)-1 ->d, Skip if Zero ; GOTO k Branch ; INCF f,d Increment F, (F)+1 ->d ; INCFSZ f,d Inc. F Skip if Zero,(F)+1 ->d, Skip if Zero ; IORLW k OR Literal of W, (W) OR k->w ; IORWF f,d OR W with F, (W) OR (F)->d ; MOVLW k Move Literal to W, k -> W ; MOVF f,d Move F, (F)-> d ; MOVWF f Move W to F (W)->(F) ; NOP No Operation
; RETFIE Return from intr. TOS->PC, 1->GIE ; RETLW k Return Literal to W TOS->PC, k->w ; RETURN k Return from Subrout. TOS->PC ; RLF f,d Rotate Left F with C,F.n->d.n+1, F.7->C, C->d.0 ; RRF f,d Rotate Righ F with C,F.n->d.n-1, F.0->C, C->d.7 ; SLEEP Go Sleep Mode ; SUBLW k Sub Literal from W, k- (W) -> W ; SUBWF f,d Sub W to F, (F)-(W) -> d ; SWAPF f,d Swap F, F.0:3->d.4:7, F.4:7->d.0:3 ; XORLW k ExOR Literal with W,(W) XOR k -> W ; XORWF f,d ExOR W with F, (W) XOR (F)-> d LIST P=16F877 ERRORLEVEL -302 ; THIS PROGRAM MAX CHECK RAM 2 BANK, ROM ~FFFH ;---------------------------------------------------- ; FILE DEFINITION ;---------------------------------------------------- ;------ BANK0 INDF EQU 00H ; Indirect Address (Reference FSR) TMR0 EQU 01H PC EQU 02H STATUS EQU 03H FSR EQU 04H ; File Select Register (Indirect Addr.) PORTA EQU 05H PORTB EQU 06H PORTC EQU 07H PORTD EQU 08H PORTE EQU 09H PCLATH EQU 0AH INTCON EQU 0BH PIR1 EQU 0CH PIR2 EQU 0DH TMR1L EQU 0EH TMR1H EQU 0FH T1CON EQU 10H TMR2 EQU 11H T2CON EQU 12H SSPBUF EQU 13H SSPCON EQU 14H CCPR1L EQU 15H CCPRLH EQU 16H CCP1CON EQU 17H
RCSTA EQU 18H TXREG EQU 19H RCREG EQU 1AH CCPR2L EQU 1BH CCPR2H EQU 1CH CCP2CON EQU 1DH ADRES EQU 1EH ADCON0 EQU 1FH ;------ BANK1 OPTIONR EQU 01H ; TRISA EQU 05H TRISB EQU 06H TRISC EQU 07H TRISD EQU 08H TRISE EQU 09H PIE1 EQU 8CH PIE2 EQU 8DH PCON EQU 8EH PR2 EQU 92H SSPADD EQU 93H SSPSTAT EQU 94H TXSTA EQU 98H SPBRG EQU 99H ADCON1 EQU 9FH ;---------------------------------------------------- ; USER DEFINE AREA ;---------------------------------------------------- SYS_SET BF1 TM_CNT GPIB_STATE INDEX IO_BUFFER ISR0_BYTE ISR1_BYTE GPIB_DAT GPIB_ADD NUM_P0 NUM_P1 NUM_P2 NUM_Q0 NUM_Q1 = 020H = 022H = 023H = 024H = 025H ; INDEX is an offset from the base address of the i/o buffer = 026H = 027H ; isr0_byte hold data from the nat9914 status regisiters which has = 028H ; yet been processed = 029H = 02AH = 02BH = 02CH = 02DH = 02EH = 02FH
NUM_Q2 NUM_R0 NUM_R1 NUM_R2 NUM_D0 NUM_D1 TEMP_R0 TEMP_R1 TEMP_R2 ;TxByte NUM_D2 PRESETH ADDRESS0 ADDRESS1 ADDRESS2 SPSR_BYTE = 030H = 031H = 032H = 033H = 034H = 035H = 038H = 039H = 03AH = 03BH = 03CH = 03DH = 03EH = 03FH = 036H = 037H INDEX1 CNT_ADD CNT03 = 040H = 042H = 041H PRESETL CHK_BIT1 CH_NUM TEMP1 RAM_DAT CNT0H CNT TEMP_W TEMP_STAT TEMP0 = 046H = 047H = 048H = 049H = 04AH = 04BH = 04CH = 04DH = 04EH = 04FH CNT0L = 050H CNT1 CNT_DAT CM_8254 = 052H = 053H = 054H TM1SEC NUM OLD0H OLD0L DIGIT0 = 056H = 057H = 058H = 059H = 05AH
DIGIT1 DIGIT2 DIGIT3 DIGIT4 DIGIT5 = 05BH = 05CH = 05DH = 05EH = 05FH DECIMAL_H DECIMAL_L CNT_DAT0 CNT_DAT1 TRIG_CS TRIG_ADD FSR_TMP FSR_IN BUFFER = 060H = 061H = 062H = 063H = 064H = 065H = 067H = 068H = 066H ;------ BANK1 ;---------------------------------------------------- ; BIT DEFINITION ;---------------------------------------------------- ;------ STATUS (03) RP0 EQU.5 TO EQU.4 PD EQU.3 ZF EQU.2 DC EQU.1 CF EQU.0 ;------ INTCON (0B) GIE EQU.7 ;all interrupt enable bit PEIE EQU.6 ;peripheral interrupt enable bit T0IE EQU.5 ;TMR0 interrupt enable bit INTE EQU.4 ;INT interrupt enable bit RBIE EQU.3 ;PORTB change intrrupt enable bit T0IF EQU.2 ;TMR0 overflow interrupt flag INTF EQU.1 ;INT interrup flag RBIF EQU.0 ;PORTB change interrupt flag ;------ PIE1 (8C) PSPIE EQU.7 ;paralle slave port interrupt enable bit ADIE EQU.6 ;ADC interrupt enable bit
RCIE EQU.5 ;serial communication interface receive TXIE EQU.4 ;serial communication interface transmit SSPIE EQU.3 ;synchronous serial port interrupt enable bit CCP1IE EQU.2 ;CCP1 interrup enable bit TMR2IE EQU.1 ;timer2 interrupt enable bit TMR1IE EQU.0 ;timer1 interrupt enable bit ;------ PIR1 (0C) PSPIF EQU.7 ;paralle slave port read/write(=1)interrupt flag ADIF EQU.6 ;ADC complete(=1) interrupt flag RCIF EQU.5 ;serial communication receive (1=buffer full) TXIF EQU.4 ;serial communication transmit(1=buffer empty) SSPIF EQU.3 ;synchronous serial port (1=TX/RX complete) CCP1IF EQU.2 ;capture1/compare1/pwm1 flag TMR2IF EQU.1 ;timer2 interrupt flag TMR1IF EQU.0 ;timer1 interrupt flag ;------ T1CON (10) T1CKPS1 EQU.5 ;TMR1 input clock prescale select (00=1 11:=8) T1CKPS0 EQU.4 ;TMR1 input clock prescale select LSB T1OSCEN EQU.3 ;TMR1 external oscillator(=1) T1NSYNC EQU.2 ;TMR1 external clock synchronization control TMR1CS EQU.1 ;TMR1 clock select (1=external/RC0 0:OSC/4) TMR1ON EQU.0 ;TMR1 on bit (1=enable 0:stop) ;------ TXSTA (98):TX state CSRC EQU.7 ;clock source in sync.mode 1:master 0:slave TX89 EQU.6 ;trans data length 1:9bit 0:8bit TXEN EQU.5 ;1:trans enable 0:disable SYNC EQU.4 ;1:syncronous mode 0:async. BRGH EQU.2 ;1:high baud rate 0:low TRMT EQU.1 ;1:TSR(trans shift register) empty 0:full TXD8 EQU.0 ;9'th bit ;------ TCSTA (18):RX state SPEN EQU.7 ;1:serial port enable 0:disable RC89 EQU.6 ;reception data length 1:9bit 0:8bit SREN EQU.5 ;don't care in async. CREN EQU.4 ;1:continuous receive enable 0:disable FERR EQU.2 ;1:framing err 0:no OERR EQU.1 ;1:overrun err 0:no RCD8 EQU.0 ;9'th bit
;------ OPTION (81) PBPU EQU.7 ;portb pull up enable (1:dis 0:en) INTEDG EQU.6 ;interrup edge select (1:rising 0:falling) RTS EQU.5 ;TMR0 signal source (1:RA4 0:internal) RTE EQU.4 ;TMR0 signal edge (1:H-to-L 0:L-to-H) PSA EQU.3 ;prescaler assignment bit (1:WDT 0:TMR0) PS2 EQU.2 ;prescaler value MSB(000:TMR0=1:2 WDT=1:1) PS1 EQU.1 ;prescaler value MSB-1 PS0 EQU.0 ;prescaler value LSB ;------ DEFINITION FOR PORTA NDA_4 EQU.4 NDA_3 EQU.3 A18 EQU.2 A17 EQU.1 A16 EQU.0 ;------ DEFINITION FOR PORTB #DEFINE ADD_L PORTB,7 #DEFINE ADD_H PORTB,6 #DEFINE IO_SDA PORTB,5 #DEFINE IO_SCL PORTB,4 #DEFINE RAM2 PORTB,3 #DEFINE RAM1 PORTB,2 #DEFINE C8254 PORTB,1 ;------ DEFINITION FOR PORTC ;------ DEFINITION FOR PORTE #DEFINE CS #DEFINE WR #DEFINE RD PORTE,2 PORTE,1 PORTE,0 ;------ DEFINITION FOR SYS_SET NN7 EQU.7 ;0:numeric 1:character NN6 EQU.6 ; NN5 EQU.5 ; NN4 EQU.4 ; NN3 EQU.3 ; NN2 EQU.2 ; ON EQU.1 ; ONLINE=0, OFFLINE=1 COM EQU.0 ; SERIAL =0, GPIB=1
;------ DEFINITION FOR CHK_BIT1 #DEFINE SIG #DEFINE N04 #DEFINE T1S #DEFINE BI_F #DEFINE SPACE #DEFINE N01 #DEFINE N02 #DEFINE N03 CHK_BIT1,7 CHK_BIT1,6 CHK_BIT1,5 CHK_BIT1,4 CHK_BIT1,3 CHK_BIT1,2 CHK_BIT1,1 CHK_BIT1,0 ;-------DEFINITION FOR GPIB_STATE I_STATE EQU.2 ; IDLE STATE R_STATE EQU.1 ; READING STATE W_STATE EQU.0 ; WRITING_STATE ;------ DEFINITION FOR ISR0_BYTE #DEFINE INT0 #DEFINE INT1 #DEFINE BI #DEFINE BO #DEFINE B_END #DEFINE SPAS #DEFINE RLC #DEFINE MAC ISR0_BYTE,7 ISR0_BYTE,6 ISR0_BYTE,5 ISR0_BYTE,4 ISR0_BYTE,3 ISR0_BYTE,2 ISR0_BYTE,1 ISR0_BYTE,0 ;------ DEFINITION FOR ISR1_BYTE GET EQU.7 ERR EQU.6 UNC EQU.5 APT EQU.4 DCAS EQU.3 MA EQU.2 SRQ EQU.1 IFC EQU.0 ;------ preset data ISR0 EQU 000H IMR0 EQU 000H ISR1 EQU 001H IMR1 EQU 001H
ADSR EQU 002H IMR2 EQU 002H EOSR EQU 002H BCR EQU 002H ACCR EQU 002H BSR EQU 003H AUXCR EQU 003H ISR2 EQU 004H ADR EQU 004H SPSR EQU 005H SPMR EQU 005H CPTR EQU 006H PPR EQU 006H DIR EQU 007H CDOR EQU 007H AUXMR EQU 005H NEWLINE EQU 00AH ;---------------------------------------------------- ; MACRO DEFINITION ;---------------------------------------------------- BANK0 MACRO BCF 3,5 ENDM BANK1 MACRO BSF 3,5 ENDM PAGE0 MACRO BCF BCF ENDM 0AH,3 0AH,4 PAGE1 MACRO BSF BCF ENDM 0AH,3 0AH,4 PAGE2 MACRO BCF BSF ENDM 0AH,3 0AH,4
PAGE3 MACRO BSF 0AH,3 BSF 0AH,4 ENDM ;---------------------------------------------------- INTRET MACRO SWAPF TEMP_STAT,W MOVWF STATUS SWAPF TEMP_W,F SWAPF TEMP_W,W RETFIE ENDM ;---------------------------------------------------- SUB16 MACRO BUF1,BUF2,BUF3,BUF4,BUF5,BUF6 LOCAL SB16 MOVF BUF4,W SUBWF BUF2,W MOVWF BUF6 MOVF BUF1,W MOVWF BF2 BTFSC STATUS,CF ;Skip if Carry=0(Borrow) GOTO SB16 DECF BF2,F SB16 MOVF BUF3,W SUBWF BF2,W MOVWF BUF5 ENDM ;---------------------------------------------------- ADD16 MACRO BUF1,BUF2,BUF3,BUF4,BUF5,BUF6 LOCAL AD16 MOVF BUF2,W ADDWF BUF4,W MOVWF BUF6 MOVF BUF1,W MOVWF BF2 BTFSS STATUS,CF ;Skip if Carry=1 GOTO AD16 INCF BF2,F AD16 MOVF BUF3,W ADDWF BF2,W MOVWF BUF5 ENDM ;------ BUF1*BUF2=BUF3(H),BUF4(L) MUL8 MACRO BUF1,BUF2,BUF3,BUF4 LOCAL MU8
CLRF BUF3 CLRF BUF4 MOVLW.8 MOVWF BUF5 ;counter=8 MOVF BUF1,W BCF STATUS,CF MU8 RRF BUF2,F BTFSC STATUS,CF ADDWF BUF3,F RRF BUF3,F RRF BUF4,F DECFSZ BUF5,F GOTO MU8 ENDM ; end of macro---------------------------------------------------- ;---------------------------------------------------- ; RESET & INTERRUPT VECTOR ;---------------------------------------------------- ORG 0 GOTO SIJAK ; PROGRAM START ORG 4 GOTO INT_RTN ; INTERRUPT ORG 5 GOTO SIJAK ; POWER ON RESET ;---------------------------------------------------- ; MAIN PROGRAM ;---------------------------------------------------- SIJAK ; Main routine 시작 BANK1 MOVLW B'10101101' ;OFF,TMR0=R4,WDT=32 rate (288mS/4MHz) MOVWF OPTIONR GOTO $+1 BANK0 MOVLW B'00000000' MOVWF INTCON GOTO $+1 MOVLW B'00000000' MOVWF PIR1 GOTO $+1 MOVLW B'00000000' ;TMR0,INT(B0) Interrupt enable ;interrupt flag clear
MOVWF T2CON MOVLW B'00110100' MOVWF T1CON GOTO $+1 ;TMR1=8 rate, 0bit=0:TMR1 disable BANK1 MOVLW B'00000000' MOVWF PIE1 CLRF PIE2 CLRF SSPADD CLRF SSPSTAT GOTO $+1 ;RS232receive,TMR1 interrupt enable ;------ TRIS REGISTER INITIALIZE BANK1 MOVLW B'00000000' ; INOUT TOCKI, OUT=RS,RW,E1 MOVWF TRISA GOTO $+1 ;2 CYCLE DELAY MOVLW B'00100001' ;ADD_L(7),ADD_H(6),IO_SDA(5),IO_SCL(4) MOVWF TRISB ;RAM2(3),RAM1(2),C8254(1),INT(0) GOTO $+1 MOVLW B'10000000' ; MOVWF TRISC GOTO $+1 MOVLW B'00000000' ;after toggle MOVWF TRISD GOTO $+1 MOVLW B'00000000' ; RD,RW,CS MOVWF TRISE GOTO $+1 MOVLW B'00000110' ; set porta data I/O MOVWF ADCON1 GOTO $+1 BANK0 CLRF ADCON0 ;internal ADConver off CLRF CCP1CON CLRF CCP2CON ;------ PORT REGISTER INITIALIZE CLRWDT BANK0 MOVLW B'00000000' MOVWF PORTA GOTO $+1 MOVLW B'11111111' ; ADD_L ADD_H IOSCA IOSCL RAM2 RAM1 8254 MOVWF PORTB GOTO $+1
MOVLW B'11111000' MOVWF PORTC GOTO $+1 MOVLW B'00000000' MOVWF PORTD GOTO $+1 MOVLW B'00000111' MOVWF PORTE GOTO $+1 ;ALE(.2)=1, WR#(.1)=1, RD#(.0)=1 DL_1 ;------ HARDWARE SAFTY TIME (1mS Delay) CLRWDT CLRF CNT CLRWDT DECFSZ CNT,F GOTO DL_1 CLR_01 ;------ CLEAR RAM (20H-07FH) MOVLW 20H MOVWF FSR CLRWDT CLRF INDF INCF FSR,F BTFSS FSR,7 GOTO CLR_01 CLR_02 ;------ CLEAR RAM (0A0H-0FFH) MOVLW 0A0H MOVWF FSR CLRWDT CLRF INDF INCFSZ FSR,F GOTO CLR_02 BSF RAM1 BSF RAM2 BSF C8254 BCF ADD_L BCF ADD_H ;*************************************************************************** BCF SPACE BSF IO_SCL BCF SYS_SET,COM BANK1 BCF PIE1,TMR1IE ; timer1 overflow interupt enable bit BANK0
BCF INTCON,GIE ;all interrupt disable BCF BI_F BCF T1S BTFSC IO_SDA BSF SYS_SET,COM ; COMMUNICATION SELECT CALL INIT9914 ; initialize nat9914 CALL INIT8254 ; initialize 8254 CALL SIO_SET ; SRIAL SET CLRF INTCON BCF INTCON,INTF BSF INTCON,INTE BSF INTCON,GIE MOVLW 0X0B ;TNR1H;65535-25000+2=53037(9E59H=0.2sec) MOVWF PRESETH ;TMR1L;4MHz/4/8=125000pulse/1sec(0.1=CF2D) MOVLW 0XEA MOVWF PRESETL MOVLW.2 MOVWF TM1SEC MOVLW.8 MOVWF CH_NUM ; DEFALUT VALUE ; 1 SEC MOVLW BUFFER MOVWF FSR_IN BSF PORTC,3 BSF PORTC,4 BSF PORTC,5 BCF BI BCF PIR1,TMR1IF ; timer1 flag clear BCF INTCON,INTF ; interupt flag clear BCF INTCON,T0IF ; timer0 flag clear BCF INTCON,T0IE ; timer0 interupt DISable BSF INTCON,INTE ; RB0 interupt enable BSF INTCON,PEIE ;peripheral interrupt enable (TMR1,SIO...) BANK1 BCF PIE1,TMR1IE ; timer1 overflow interupt enable bit BSF PIE1,RCIE BANK0 BSF INTCON,GIE ;all interrupt enable BCF T1CON,0 ;----------------------------------------------------------
IDL_LP PARSE CHSET ;------ IDLE LOOP START--------- BTFSS BI_F GOTO IDL_LP BCF BI_F ; ;---------------------------- MOVLW BUFFER ; SEARCH FOR *IDN? MOVWF FSR MOVF INDF,W XORLW '*' BTFSS STATUS,ZF GOTO CHSET INCF FSR,F MOVF INDF,W XORLW 'I' BTFSS STATUS,ZF GOTO CHSET INCF FSR,F MOVF INDF,W XORLW 'D' BTFSS STATUS,ZF GOTO CHSET INCF FSR,F MOVF INDF,W XORLW 'N' BTFSS STATUS,ZF GOTO CHSET INCF FSR,F MOVF INDF,W XORLW '?' BTFSS STATUS,ZF GOTO CHSET CALL SEND_IDN GOTO CLR_BUF ; SEARCH FOR CHANNEL SET MOVLW BUFFER MOVWF FSR MOVF INDF,W XORLW 'C' BTFSS STATUS,ZF GOTO TIMESET INCF FSR,F MOVF INDF,W XORLW 'H' BTFSS STATUS,ZF
GOTO TIMESET INCF FSR,F MOVF INDF,W XORLW ':' BTFSS STATUS,ZF GOTO TIMESET INCF FSR,F MOVF INDF,W MOVWF CH_NUM MOVLW 0X30 SUBWF CH_NUM,F GOTO CLR_BUF ;******************************* TIMESET ; SEARCH FOR TIME SET MOVLW BUFFER MOVWF FSR MOVF INDF,W XORLW 'T' BTFSS STATUS,ZF GOTO SDCM INCF FSR,F MOVF INDF,W XORLW 'M' BTFSS STATUS,ZF GOTO SDCM TM00SEC INCF FSR,F MOVF INDF,W XORLW 'S' BTFSS STATUS,ZF GOTO TM01SEC GOTO TIME1SEC TM01SEC MOVF INDF,W XORLW 'M' BTFSS STATUS,ZF GOTO SDCM MOVLW.2 ; MOVWF TM1SEC ; 1 SEC MOVLW 0XFF MOVWF PRESETL MOVLW 0XFF MOVWF PRESETH INCF FSR,F
MOVF INDF,W XORLW ' ' BTFSS STATUS,ZF GOTO NEXT001 GOTO NEXT123 NEXT001 MOVF INDF,W MOVWF DECIMAL_H MOVLW 0X30 SUBWF DECIMAL_H,F BTFSS STATUS,ZF GOTO NN_10 GOTO NEXT123 ; DECIMAL_H - 0X30 NN_10 ; SUBTRACT 186A=6250 PULSE 186A pulse*2*8u sec/pulse= 0.1 sec MOVLW 0X6A SUBWF PRESETL,F ; PRESETL - 0X6A BTFSS STATUS,CF DECF PRESETH,F MOVLW 0X18 SUBWF PRESETH,F ; PRESETH - 0X18 DECFSZ DECIMAL_H,F ; 186A = 6250 PULSE GOTO NN_10 GOTO SKIP_S NEXT123 BSF SPACE SKIP_S INCF FSR,F MOVF INDF,W MOVWF DECIMAL_L XORLW ' ' BTFSS STATUS,ZF GOTO NEXT234 GOTO TIME1SEC NEXT234MOVLW 0X30 SUBWF DECIMAL_L,F BTFSS STATUS,ZF GOTO NN_01 BTFSC SPACE GOTO TIME1SEC GOTO CLR_BUF NN_01 ; SUBTRACT 0271=625 PULSE 0271 pulse*2*8u sec/pulse= 0.01 sec MOVLW 0X71 SUBWF PRESETL,F
BTFSS DECF STATUS,CF PRESETH,F MOVLW 0X02 SUBWF PRESETH,F DECFSZ DECIMAL_L,F GOTO NN_01 GOTO CLR_BUF ; 04E1 TIME1SEC BCF SPACE MOVLW 0X0B ; MOVWF PRESETH ; MOVLW 0XEA MOVWF PRESETL SDCM MOVLW.2 ; MOVWF TM1SEC ; 1 SEC GOTO CLR_BUF ;***************************************** ; SEARCH FOR 'SEND' MOVLW BUFFER MOVWF FSR MOVF INDF,W XORLW 'S' BTFSS STATUS,ZF GOTO END_SK INCF FSR,F MOVF INDF,W XORLW 'E' BTFSS STATUS,ZF GOTO END_SK INCF FSR,F MOVF INDF,W XORLW 'N' BTFSS STATUS,ZF GOTO END_SK INCF FSR,F MOVF INDF,W XORLW 'D' BTFSS STATUS,ZF GOTO END_SK GOTO SEND_SD GOTO CLR_BUF END_SK ; SEARCH FOR 'SEND'
MOVLW BUFFER MOVWF FSR MOVF INDF,W XORLW 'E' BTFSS STATUS,ZF GOTO CLR_BUF INCF FSR,F MOVF INDF,W XORLW 'N' BTFSS STATUS,ZF GOTO CLR_BUF INCF FSR,F MOVF INDF,W XORLW 'D' BTFSS STATUS,ZF GOTO CLR_BUF CALL INIT9914 CALL INIT8254 BANK1 BCF PIE1,TMR1IE ; timer1 overflow interupt DISABLE BANK0 BCF T1CON,0 CLR_BUF BCF SPACE MOVLW BUFFER MOVWF FSR_IN GOTO IDL_LP ; CLRF BUFFER ; INPUT START VALUE FROM C8254 SEND_SD ;----------------------------------------------------------------- MOVF TM1SEC,W MOVWF TM_CNT BCF PIR1,TMR1IF MOVF PRESETH,W MOVWF TMR1H MOVF PRESETL,W ; MOVWF TMR1L BANK1 BSF PIE1,TMR1IE ; timer1 overflow interupt enable bit BANK0 BSF T1CON,0 ; TIMER1 ON MOVF CH_NUM,W MOVWF CNT
CLRF CNT_ADD MOVLW 0XA0 MOVWF INDEX1 MOVLW SPSR CALL GPIB_RD MOVF GPIB_DAT,W MOVWF SPSR_BYTE ; GPIB 에의한송신준비 MOVLW SPMR BCF SPSR_BYTE,6 BSF SPSR_BYTE,4 MOVF SPSR_BYTE,W LP_INIT MOVLW AUXCR ; MOVLW 0X98 ; BCF CNT_ADD,1 ; COUNT0 BCF CNT_ADD,0 CALL RD_54 ; READ FROM 8254 MOVF INDEX1,W ; MOVWF FSR MOVF CNT_DAT0,W ; LOW BYTE -> RAM_DAT(INDEX1) MOVWF INDF INCF INDEX1,F ; INDEX1+1 MOVF INDEX1,W MOVWF FSR MOVF CNT_DAT1,W ; HIGH BYTE -> RAM_DAT(INDEX1+1) MOVWF INDF ;-------------- BCF CNT_ADD,1 ; COUNT1 BSF CNT_ADD,0 CALL RD_54 ; READ LOW BYTE INCF INDEX1,F MOVF INDEX1,W MOVWF FSR
MOVF CNT_DAT0,W MOVWF INDF ; LOW BYTE-> RAM_DAT(INDEX0+2) INCF INDEX1,F MOVF INDEX1,W MOVWF FSR MOVF CNT_DAT1,W MOVWF INDF ;--------------- BSF CNT_ADD,1 BCF CNT_ADD,0 CALL RD_54 ; COUNT2 ; HIGH BYTE-> RAM(INDEX0+3) INCF INDEX1,F MOVF INDEX1,W MOVWF FSR MOVF CNT_DAT0,W MOVWF INDF INCF INDEX1,F MOVF INDEX1,W MOVWF FSR MOVF CNT_DAT1,W MOVWF INDF INCF INDEX1,F MOVLW B'00000100' ADDWF CNT_ADD,F DECFSZ CNT,F GOTO LP_INIT ; INDEX0+6 ; LOW BYTE -> RAM(INDEX0+4) ; HIGH BYTE -> RAM( INDEX0+5) SEND_LP BTFSS T1S GOTO SEND_LP BCF T1S MOVF CH_NUM,W ; COUNTER LATCH COMMAND MOVWF CNT CLRF CNT_ADD LATCH MOVLW B'00000000' ; COUNTER LATCH MOVWF CM_8254 ; COMMAND BSF CNT_ADD,0 ; COUNTER0 BSF CNT_ADD,1 ; CALL WR_8254 ;------------------------------- MOVLW B'01000000' ; COUNTER LATCH MOVWF CM_8254 ; COMMAND BSF CNT_ADD,0 ; COUNTER1 BSF CNT_ADD,1
CALL WR_8254 ;------------------------------- MOVLW B'10000000' ; COUNTER LATCH MOVWF CM_8254 ; COMMAND BSF CNT_ADD,0 ; COUNTER2 BSF CNT_ADD,1 CALL WR_8254 MOVLW B'00000100' ADDWF CNT_ADD,F DECFSZ CNT,F GOTO LATCH LP2 ;------------------------------------------------ ; READ COUNT VALUE FROM 8254 ;-------------------------- MOVF CH_NUM,W MOVWF CNT CLRF CNT_ADD MOVLW 0XA0 MOVWF INDEX1 ;;*************************************** BCF CNT_ADD,1 ; COUNT0 BCF CNT_ADD,0 ; CALL RD_54 ; READ FROM 8254 MOVF CNT_DAT0,W ; CNT_DAT0-> CNT0L MOVWF CNT0L MOVF CNT_DAT1,W ; CNT_DAT1-> CNT0H MOVWF CNT0H MOVF INDEX1,W ; DATA(INDEX1)-> OLD0L MOVWF FSR ; MOVF INDF,W ; MOVWF OLD0L ; MOVF CNT_DAT0,W ; CNT_DAT0 -> DATA(INDEX1) MOVWF INDF ; INCF INDEX1,F ; MOVF INDEX1,W ; MOVWF FSR ; DATA(INDEX1+1)-> OLD0H MOVF INDF,W ; MOVWF OLD0H ; MOVF CNT_DAT1,W ; CNT_DAT1 -> DATA(INDEX+1) MOVWF INDF ;
CALL SUB_DAT ; SUBTRACT MOVF CNT0H,W ; HEXA CONVERSION OF HIGH BYTE MOVWF NUM ; CALL HEX_CONV ; GPIB00 BTFSC SYS_SET,COM ; SERIAL=0 GOTO GPIB00 MOVF DIGIT1,W CALL TX_DAT MOVF DIGIT0,W CALL TX_DAT GOTO SERIAL00 CALL WAIT_BO MOVLW CDOR MOVF DIGIT1,W CALL WAIT_BO MOVLW CDOR MOVF DIGIT0,W SERIAL00 MOVF CNT0L,W MOVWF NUM CALL HEX_CONV GPIB01 BTFSC SYS_SET,COM GOTO GPIB01 MOVF DIGIT1,W CALL TX_DAT MOVF DIGIT0,W CALL TX_DAT GOTO COUNT1 CALL WAIT_BO MOVLW CDOR MOVF DIGIT1,W
CALL WAIT_BO MOVLW CDOR MOVF DIGIT0,W COUNT1 ;************************************************************ BCF CNT_ADD,1 ; COUNT1 BSF CNT_ADD,0 CALL RD_54 MOVF CNT_DAT0,W ; LOW BYTE-> RAM_DAT(INDEX0+2) MOVWF CNT0L MOVF CNT_DAT1,W MOVWF CNT0H INCF INDEX1,F MOVF INDEX1,W MOVWF FSR MOVF INDF,W ; HIGH BYTE-> RAM(INDEX0+3) MOVWF OLD0L MOVF CNT_DAT0,W MOVWF INDF INCF INDEX1,F MOVF INDEX1,W MOVWF FSR MOVF INDF,W MOVWF OLD0H MOVF CNT_DAT1,W MOVWF INDF CALL SUB_DAT MOVF CNT0H,W MOVWF NUM CALL HEX_CONV GPIB02 BTFSC GOTO MOVF CALL MOVF CALL GOTO SYS_SET,COM GPIB02 DIGIT1,W TX_DAT DIGIT0,W TX_DAT SERIAL02
CALL WAIT_BO MOVLW CDOR MOVF DIGIT1,W CALL WAIT_BO MOVLW CDOR MOVF DIGIT0,W SERIAL02 MOVF CNT0L,W MOVWF NUM CALL HEX_CONV GPIB03 BTFSC SYS_SET,COM GOTO GPIB03 MOVF DIGIT1,W CALL TX_DAT MOVF DIGIT0,W CALL TX_DAT GOTO COUNT2 CALL WAIT_BO MOVLW CDOR MOVF DIGIT1,W CALL WAIT_BO MOVLW CDOR MOVF DIGIT0,W COUNT2 ;******************************************************* BSF CNT_ADD,1 ; COUNT2 BCF CNT_ADD,0 CALL RD_54 MOVF CNT_DAT0,W ; LOW BYTE -> RAM(INDEX0+4)
MOVWF CNT0L MOVF CNT_DAT1,W MOVWF CNT0H INCF INDEX1,F MOVF INDEX1,W MOVWF FSR MOVF INDF,W MOVWF OLD0L MOVF CNT_DAT0,W MOVWF INDF INCF INDEX1,F MOVF INDEX1,W MOVWF FSR MOVF INDF,W MOVWF OLD0H MOVF CNT_DAT1,W MOVWF INDF CALL SUB_DAT MOVF CNT0H,W MOVWF NUM CALL HEX_CONV GPIB04 BTFSC SYS_SET,COM GOTO GPIB04 MOVF DIGIT1,W CALL TX_DAT MOVF DIGIT0,W CALL TX_DAT GOTO SERIAL04 CALL WAIT_BO MOVLW CDOR MOVF DIGIT1,W CALL WAIT_BO MOVLW CDOR MOVF DIGIT0,W
SERIAL04 MOVF CNT0L,W MOVWF NUM CALL HEX_CONV BTFSC SYS_SET,COM GOTO GPIB05 MOVF DIGIT1,W CALL TX_DAT MOVF DIGIT0,W CALL TX_DAT GOTO NEXT_SS GPIB05 CALL WAIT_BO MOVLW CDOR MOVF DIGIT1,W CALL WAIT_BO MOVLW CDOR MOVF DIGIT0,W NEXT_SS INCF INDEX1,F ; INDEX0+6 MOVLW B'00000100' ADDWF CNT_ADD,F DECFSZ CNT,F GOTO LP2 BTFSC SYS_SET,COM GOTO GPIB06 MOVLW 0X0A CALL TX_DAT GOTO ENDOOP GPIB06 CALL WAIT_BO MOVLW CDOR MOVLW 0X0A ENDOOP BTFSS BI_F
GOTO SEND_LP BCF BI_F GOTO PARSE ;---------------------------------------------------- ; SUBROUTINE ; time delay ;---------------------------------------------------- ;------ 256mS delay --------------------------------- WAIT256 CLRF CNT1 CLRF CNT WAIT_1 CLRWDT DECFSZ CNT,F GOTO WAIT_1 DECFSZ CNT1,F GOTO WAIT_1 RETURN SIO_SET ;------ serial port set BANK1 MOVLW B'00100100' MOVWF TXSTA MOVLW.12 MOVWF SPBRG BANK0 MOVLW B'10010000' MOVWF RCSTA RETURN ; enable, BRGH=1(high baud) ;BAUD=19200(err=0.16%)/4MHz TX_DAT ;------ data transmission to serial port BCF PIR1,TXIF MOVWF TXREG ;transmit start TXL1 CLRWDT BTFSS PIR1,TXIF GOTO TXL1 RETURN ;---------------------------------------------------- ; NUMERIC SUBROUTINE ;---------------------------------------------------- ; 24 BIT DIVIDE 24 비트나눗셈알고리즘 ; ; divid ; PDIV NUM_Q
; NUM_D ----------- ; NUM_P ; ; NUM_R ; DIVIDEND ; NUM_P2, NUM_P1, NUM_P0 ; QUATIANT ; NUM_Q2, NUM_Q1, NUM_Q0 ; REMNAT : NUM_R2, NUM_R1, NUM_R0 ; DIVIDER : NUM_D2, NUM_D1, NUM_D0 DIV16BIT CLRF NUM_R0 CLRF NUM_R1 CLRF NUM_R2 CLRF NUM_Q0 CLRF NUM_Q1 CLRF NUM_Q2 MOVLW.24 MOVWF CNT DIV_1 BCF STATUS,CF RLF NUM_P0,F RLF NUM_P1,F RLF NUM_P2,F RLF NUM_R0,F RLF NUM_R1,F RLF NUM_R2,F MOVF NUM_R0,W MOVWF TEMP_R0 MOVF NUM_R1,W MOVWF TEMP_R1 MOVF NUM_R2,W MOVWF TEMP_R2 MOVF NUM_D0,W ; NUM_R0-NUM_D0-> NUM_R0 SUBWF TEMP_R0,F ; R0- D0-> R0 BTFSS STATUS,CF ; BORROW CHECK GOTO BORROW_Y1 ; CF=0 MOVF NUM_D1,W GOTO SUB_NEXT1 BORROW_Y1 INCF NUM_D1,W SUB_NEXT1 SUBWF TEMP_R1,F ; TEMP_R1-NUM_D1-> TEMP_R1 BTFSS STATUS,CF ; BORROW CHECK GOTO BORROW_Y2 MOVF NUM_D2,W
GOTO SUB_NEXT2 BORROW_Y2 INCF NUM_D2,W SUB_NEXT2 SUBWF TEMP_R2,F BTFSS STATUS,CF ; BORROW CHECK GOTO NEG ; CF =0 BORROW HAPPEN BSF STATUS,CF ; CF =1 BORROW NOT HAPPEN RLF NUM_Q0,F RLF NUM_Q1,F RLF NUM_Q2,F MOVF TEMP_R0,W MOVWF NUM_R0 MOVF TEMP_R1,W MOVWF NUM_R1 MOVF TEMP_R2,W MOVWF NUM_R2 GOTO DIV_NEXT NEG BCF STATUS,CF ; NUM_R-NUM_D <0 RLF NUM_Q0,F RLF NUM_Q1,F RLF NUM_Q2,F DIV_NEXT DECFSZ CNT,F GOTO DIV_1 RETURN ASCII_CONV ; 2진수 data를 10진 ASCII data로변환 BCF SIG MOVLW 0X01 ;---------------------- MOVWF NUM_D2 ;100000 =186A0H MOVLW 0X86 ; MOVWF NUM_D1 MOVLW 0XA0 MOVWF NUM_D0 CALL DIV16BIT MOVLW 0X30 ADDWF NUM_Q0,W MOVWF DIGIT5 MOVLW '0' XORWF DIGIT5,W
BTFSS STATUS,ZF GOTO N2710H MOVLW ' ' BTFSS SIG MOVWF DIGIT5 GOTO Y2710H N2710H BSF SIG Y2710H MOVLW 0X00 ;--------------------- MOVWF NUM_D2 ; 10000 =2710H MOVLW 0X27 MOVWF NUM_D1 MOVLW 0X10 MOVWF NUM_D0 MOVF NUM_R0,W MOVWF NUM_P0 MOVF NUM_R1,W MOVWF NUM_P1 MOVF NUM_R2,W MOVWF NUM_P2 CALL DIV16BIT MOVLW ADDWF MOVWF MOVLW XORWF BTFSS GOTO MOVLW BTFSS MOVWF GOTO N03E8H BSF Y03E8H 0X30 NUM_Q0,W DIGIT4 '0' DIGIT4,W STATUS,ZF N03E8H ' ' SIG DIGIT4 Y03E8H SIG MOVLW 0X00 ;-------------------- MOVWF NUM_D2 ; 1000= 03E8H MOVLW 0X03 MOVWF NUM_D1 MOVLW 0XE8 MOVWF NUM_D0 MOVF NUM_R0,W MOVWF NUM_P0 MOVF NUM_R1,W
MOVWF NUM_P1 MOVF NUM_R2,W MOVWF NUM_P2 CALL DIV16BIT MOVLW 0X30 ADDWF NUM_Q0,W MOVWF DIGIT3 MOVLW '0' XORWF DIGIT3,W BTFSS STATUS,ZF GOTO N64H MOVLW ' ' BTFSS SIG MOVWF DIGIT3 GOTO Y64H N64H BSF SIG Y64H MOVLW 0X00 ;------------------ MOVWF NUM_D2 ; 100 = 64H MOVLW 0X00 MOVWF NUM_D1 MOVLW 0X64 MOVWF NUM_D0 MOVF NUM_R0,W MOVWF NUM_P0 MOVF NUM_R1,W MOVWF NUM_P1 MOVF NUM_R2,W MOVWF NUM_P2 CALL DIV16BIT MOVLW 0X30 ADDWF NUM_Q0,W MOVWF DIGIT2 MOVLW '0' XORWF DIGIT2,W BTFSS STATUS,ZF GOTO N10H MOVLW ' ' BTFSS SIG MOVWF DIGIT2 GOTO Y10H N10H BSF SIG Y10H
MOVLW 0X00 ;------------------ MOVWF NUM_D2 MOVLW 0X00 MOVWF NUM_D1 MOVLW.10 MOVWF NUM_D0 MOVF NUM_R0,W MOVWF NUM_P0 MOVF NUM_R1,W MOVWF NUM_P1 MOVF NUM_R2,W MOVWF NUM_P2 CALL DIV16BIT MOVLW 0X30 ADDWF NUM_Q0,W MOVWF DIGIT1 MOVLW '0' XORWF DIGIT1,W BTFSS STATUS,ZF GOTO N1H MOVLW ' ' BTFSS SIG MOVWF DIGIT1 GOTO Y1H N1H BSF SIG Y1H ;----------------------------------- MOVF NUM_R0,W MOVLW 0X30 ADDWF NUM_R0,W MOVWF DIGIT0 RETURN SUB_DAT ; SUBTRACT CNT FROM OLD DATA MOVF CNT0L,W SUBWF OLD0L,W ; OLD0L - CNT0L-> CNT0L MOVWF CNT0L BTFSS STATUS,CF ; DECF OLD0H,F ; OLD0H-1 MOVF CNT0H,W SUBWF OLD0H,W ; OLD0H- CNT0H -> CNT0H
MOVWF CNT0H RETURN HEX_CONV ; 2진 data를 HEXA ASCII data로변환 SWAPF NUM,W ANDLW B'00001111' MOVWF NUM_P1 MOVF NUM_P1,W SUBLW.9 ;9 - HEX BTFSS STATUS,CF GOTO H40H MOVF NUM_P1,W ADDLW 0X30 MOVWF DIGIT1 GOTO HEX2 H40H MOVF NUM_P1,W ADDLW 0X37 MOVWF DIGIT1 HEX2 H40L NEXT_H MOVF NUM,W ANDLW B'00001111' MOVWF NUM_P1 MOVF NUM_P1,W SUBLW.9 BTFSS STATUS,CF GOTO H40L MOVF NUM_P1,W ADDLW 0X30 MOVWF DIGIT0 GOTO NEXT_H MOVF NUM_P1,W ADDLW 0X37 MOVWF DIGIT0 RETURN ;**************************************************** ; EXTERNAL interface subroutine ;**************************************************** ; I2C SUBROUTINE I2C_SEND MOVWF BF1
IC_1 MOVLW.8 MOVWF CNT BTFSC BF1,7 BSF IO_SDA BTFSS BF1,7 BCF IO_SDA BSF IO_SCL RLF BF1 BCF IO_SCL DECFSZ CNT GOTO IC_1 RETLW 0 ; GPIB SUBROUTINE INIT9914 ; initialize nat9914 GPIB 초기화프로그램 MOVLW AUXMR ; SWITCH TO 9914 MODE MOVLW 0X15 ;sw9914=0x15) MOVLW AUXCR ; page in accessory registor ; auxcr =3 MOVLW 0X1C ; OX1C = chip reset, clear page in registor ;---- clear status registor CLRF ISR0 CLRF ISR1 ;--------set clock speed MOVLW AUXCR ; page in accessory registor ; auxcr =3 MOVLW 0X9F MOVLW ACCR ; ; MOVLW B'00100100' ; ICR 4Mhz icr MOVLW AUXCR ; clear page in resistor
MOVLW 0X9C ;------------------------------------ MOVLW AUXCR ; MOVLW 0X97 ; set very short T1 delay (~vstdl) ;-------------enable interrupt MOVLW IMR0 ; INTERUPT MASK 0 SET MOVLW B'00100000' ;MOVLW B'00100000' ;---------------------------------------- MOVLW IMR1 ; INTERUPT MASK 1 SET MOVLW B'10001000' ;MOVLW B'00000000' ;----------------------------------------------------- MOVLW AUXCR ; page in interupt mask resistor2 ; MOVLW 0X1E ;(piimr2) MOVLW IMR2 MOVLW B'10000000' ; clear global interupt bit MOVLW AUXCR ; CLEAR PAGE IN REGISTOR MOVLW 0X9C ;-------------configure the newline character to end imcoming and outgoing MOVLW AUXCR ; auxcr=3
MOVLW 0X9E ; (pieosr) page in end of string resistor MOVLW EOSR ; esor=2 MOVLW NEWLINE ; ; MOVLW AUXCR ; auxcr=3 MOVLW 0X9C ; clear page in resistor ;-------------- MOVLW AUXCR ; page in accessory registor MOVLW 0X9F ; MOVLW ACCR MOVLW B'10001100' ;accra MOVLW AUXCR ; clear page in resistor MOVLW 0X9C ; c_piaccr ;------------------- set inv active low MOVLW AUXCR ; page in accessory registor ; auxcr =3 MOVLW 0X9F MOVLW ACCR ; ; MOVLW B'10100000' ; ICR 4Mhz
MOVLW AUXCR ; clear page in resistor MOVLW 0X9C ;------------ set the gpib address of the device MOVLW ADR MOVLW 0X02 ; set gpib address ;------------- enable the device to recive data and command MOVLW AUXCR MOVLW 0X00 ; (c_nswrst) clear software reset RETURN ;GPIB WRITE*********************************** GPIB_WR ; p16f74(data) -> nat9914 BCF RD BANK1 CLRF TRISD BANK0 BCF WR ; write enable MOVF GPIB_ADD,W MOVWF PORTD BSF ADD_L BCF ADD_L MOVF GPIB_DAT,W MOVWF PORTD BCF CS ; chip enable BSF CS ; chip disable BSF WR ; write disable BSF RD RETURN GPIB_RD ; nat9914(data) -> p16f74 BCF RD BANK1 CLRF TRISD BANK0 MOVF GPIB_ADD,W MOVWF PORTD BSF ADD_L
BCF ADD_L BANK1 MOVLW 0FFH MOVWF TRISD BANK0 BSF RD ; enable dbin BCF CS ; chip enable MOVF PORTD,W ; portd-> w ; w-> gpib_dat BSF CS ; chip disable BCF RD ; disable dbin BANK1 CLRF TRISD BANK0 BSF RD RETURN WAIT_BO ;------------------------- MOVLW ISR0 ; ISR0 register를읽어온다음 ; Byte out(bo) bit 가 set 되어있는지확인하여 CALL GPIB_RD ; BO가 set 되어있지않으면대기되어있으면 return MOVF GPIB_DAT,W MOVWF ISR0_BYTE BTFSS BO GOTO WAIT_BO RETURN SEND_IDN ; Query *IDN? 에대해응답하기위한 subroutine MOVLW SPSR ; Serial Poll Status Register - 데이터전송을위한준비시작 ; 첫번재단계로현재 nat9914의 spsr상태를 check CALL GPIB_RD ; 하여 SPSR_BYTE에저장 MOVF GPIB_DAT,W MOVWF SPSR_BYTE MOVLW SPMR ; ; BCF SPSR_BYTE,6 ; clear request service bit BSF SPSR_BYTE,4 ; SET Message Available bit MOVF SPSR_BYTE,W MOVLW AUXCR ; MOVLW 0X98 ; Set Request Service bit 2 (RSV2)
CALL WAIT_BO ; 데이터전송준비끝. MOVLW CDOR ; 데이터를 CDOR register에전송시작 MOVLW 'K' CALL WAIT_BO MOVLW CDOR MOVLW 'T' CALL WAIT_BO MOVLW CDOR MOVLW 'G' CALL WAIT_BO MOVLW CDOR MOVLW '-' CALL WAIT_BO MOVLW CDOR MOVLW 'D' CALL WAIT_BO MOVLW CDOR MOVLW 'A'
CALL WAIT_BO MOVLW CDOR MOVLW 'Q' CALL WAIT_BO MOVLW CDOR MOVLW 0X0A RETURN ; ************************************************************* ; RAM SUBROUTINE ;************************************************************** RD_RAM BSF RD BANK1 CLRF TRISD BANK0 MOVF ADDRESS0,W MOVWF PORTD BSF ADD_L BCF ADD_L MOVF ADDRESS1,W MOVWF PORTD BSF ADD_H BCF ADD_H MOVF ADDRESS2,W MOVWF PORTA BANK1 MOVLW 0FFH MOVWF TRISD ;make PORTD input BANK0 BTFSC ADDRESS2,3 GOTO H_ADDR BCF RAM1 ; chip enable BCF RD ; read enable MOVF PORTD,W ;read data and move to W MOVWF RAM_DAT BSF RD ; read disable BSF RAM1 ; chip disable GOTO END_R
H_ADDR BCF RAM2 ; chip enable BCF RD ; read enable MOVF PORTD,W ;read data and move to W MOVWF RAM_DAT BSF RD ; read disable BSF RAM2 ; chip disable END_R RETURN ;CHANNEL ADDRESS WRITE ------ write (source<-adata) ; WR_RAM BSF WR BANK1 ; CLRF TRISD ; MAKE PORTD OUTPUT BANK0 MOVF ADDRESS0,W MOVWF PORTD BSF ADD_L BCF ADD_L MOVF ADDRESS1,W MOVWF PORTD BSF ADD_H BCF ADD_H MOVF ADDRESS2,W MOVWF PORTA BTFSC ADDRESS2,3 ; 0000 1000 GOTO HW_ADD BCF RAM1 ; chip enable MOVF RAM_DAT,W ; 8 BIT DATA MOVWF PORTD BCF WR ; write enable BSF WR ; write disable BSF RAM1 ; chip disable GOTO END_W HW_ADD BCF RAM2 ; chip enable MOVF RAM_DAT,W ; 8 BIT DATA MOVWF PORTD BCF WR ; write enable BSF WR ; write disable BSF RAM2 ; chip disable END_W BANK1 MOVLW 0XFF MOVWF TRISD
BANK0 RETURN INC_ADD MOVLW.1 ADDWF ADDRESS0,F BTFSS STATUS,CF GOTO END_INC MOVLW.1 ADDWF ADDRESS1,F BTFSS STATUS,CF GOTO END_INC INCF ADDRESS2,W ANDLW B'00001111' MOVWF ADDRESS2 END_INC RETURN RD_54 ;************************************************************ ; 8254 SUBROUTINE BSF WR BANK1 CLRF TRISD ;make PORTD OUT PUT BANK0 MOVF CNT_ADD,W MOVWF PORTD BSF ADD_L BCF ADD_L BANK1 MOVLW 0FFH MOVWF TRISD ;make PORTD input BANK0 BCF C8254 ; chip enable BCF RD ; read enable MOVF PORTD,W ;read data and move to W MOVWF CNT_DAT0 BSF RD ; read disable BCF RD ; read enable MOVF PORTD,W ;read data and move to W MOVWF CNT_DAT1 BSF RD BSF C8254 ; chip disable RETURN ;CHANNEL ADDRESS WRITE ------ write (source<-adata)
; ; input data ; 8254cm - 8254 command ; WR_8254 BSF RD BANK1 ; CLRF TRISD ; MAKE PORTD OUTPUT BANK0 MOVF CNT_ADD,W MOVWF PORTD BSF ADD_L BCF ADD_L ; ADDRESS LATCH BCF C8254 ; chip enable MOVF CM_8254,W ; 8254 command Set MOVWF PORTD BCF WR ; write enable BSF WR ; write disable BSF C8254 ; chip disable BANK1 MOVLW 0XFF MOVWF TRISD BANK0 RETURN INIT8254 MOVF CH_NUM,W MOVWF CNT CLRF CNT_ADD LP3 MOVLW B'00110000' ; 0011 0000 set counter 0 as mode0 MOVWF CM_8254 BSF CNT_ADD,0 ; command 0000 0011 BSF CNT_ADD,1 ; 0000 0111 CALL WR_8254 MOVLW 0XFF ; initial value of lsb MOVWF CM_8254 BCF CNT_ADD,0 ; counter0 BCF CNT_ADD,1 CALL WR_8254 MOVLW 0XFF ; msb MOVWF CM_8254 BCF CNT_ADD,0 BCF CNT_ADD,1
CALL WR_8254 ;------------------------------- MOVLW 0X70 ; 0111 0000 set counter 1 as mode0 MOVWF CM_8254 BSF CNT_ADD,0 ; BSF CNT_ADD,1 CALL WR_8254 MOVLW 0XFF MOVWF CM_8254 BSF CNT_ADD,0 BCF CNT_ADD,1 CALL WR_8254 ; LSB MOVLW 0XFF ; MSB MOVWF CM_8254 BSF CNT_ADD,0 BCF CNT_ADD,1 CALL WR_8254 ;------------------------------- MOVLW 0XB0 ; 1011 0000 set counter 2 as mode0 MOVWF CM_8254 BSF CNT_ADD,0 BSF CNT_ADD,1 CALL WR_8254 MOVLW 0XFF MOVWF CM_8254 BSF CNT_ADD,1 BCF CNT_ADD,0 CALL WR_8254 MOVLW 0XFF MOVWF CM_8254 BSF CNT_ADD,1 BCF CNT_ADD,0 CALL WR_8254 MOVLW B'00000100' ADDWF CNT_ADD,F DECFSZ CNT,F GOTO LP3 RETURN ;---------------------------------------------------- ; INTERRUPT SERVICE ROUTINE
;---------------------------------------------------- INT_RTN MOVWF TEMP_W ; W-> TEMP_W SWAPF STATUS,W MOVWF TEMP_STAT BTFSC PIR1,TMR1IF GOTO TM1INT BTFSC INTCON,INTF ; GPIB INT GOTO GPIB_INT BTFSC INTCON,T0IF ; TIMER1 INT GOTO TMR0_INT BTFSC PIR1,RCIF GOTO SERIAL BTFSC INTCON,RBIF GOTO RBCNG_INT INTRET TMR0_INT BCF INTCON,T0IF INTRET TM1INT BCF PIR1,TMR1IF MOVF PRESETH,W MOVWF TMR1H MOVF PRESETL,W MOVWF TMR1L DECFSZ TM_CNT,F GOTO END_TM1 BSF T1S MOVF TM1SEC,W MOVWF TM_CNT END_TM1 INTRET RBCNG_INT BCF INTCON,RBIF INTRET SERIAL BCF PIR1,RCIF MOVF FSR_IN,W MOVWF FSR MOVF RCREG,W MOVWF INDF INCF FSR_IN,F XORLW 0X0A BTFSS STATUS,ZF
GOTO END_SER BSF BI_F MOVLW BUFFER MOVWF FSR_IN END_SER INTRET GPIB_INT ; nat9914 interupt subroutine BCF INTCON,INTF MOVLW ISR0 ; check interupt source CALL GPIB_RD MOVF GPIB_DAT,W MOVWF ISR0_BYTE ; BTFSC BI GOTO BYTE_IN BYTE_IN MOVF FSR_IN,W MOVWF FSR MOVLW DIR CALL GPIB_RD MOVF GPIB_DAT,W MOVWF INDF INCF FSR_IN,F BCF BI ; gpib reading state BTFSS B_END GOTO INT_RET BSF BI_F BCF B_END MOVLW BUFFER MOVWF FSR_IN INTRET BYTE_OUT INTRET ERR_STATE INTRET INT_RET INTRET END ; end of program ; gpib writing state