Proton BASIC Compiler - Simple iButton Reader


  • Pic® Basic


  • Simple iButton Reader

    A simple iButton reader using the MikroElektonika EasyPic7 board with a PIC18F45K22 running at 4Mhz internal clock. The readings are displayed on the graphic display.
    The inner connection of the ibutton holder is connected to PORTE.1 with a 4K7 pullup resistor to supply and the outer connection to ground.


    [PHP]
    '************************************************* ***************
    '* Name : iButton.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 22/12/2012 *
    '* Version : 1.0 *
    '* Notes : MIKROELECTRONIKA BOARD EasyPicV7 *
    '* : Using KS108 Graphics Display & Internal Font *
    '* : Proton Plus Compiler *
    '************************************************* ***************
    '
    '
    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings

    Device = 18F45K22

    Declare Reminders Off
    @ CONFIG_REQ = 0 ; Override Compiler's configuration settings
    Asm-
    Config FOSC = INTIO67 ;Internal oscillator block
    Config PLLCFG = OFF ;Oscillator used directly
    Config PRICLKEN = On ;Primary clock is always enabled
    Config FCMEN = OFF ;Fail-Safe Clock Monitor disabled
    Config IESO = OFF ;Oscillator Switchover mode disabled
    Config PWRTEN = OFF ;Power up timer disabled
    Config BOREN = SBORDIS ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
    Config BORV = 190 ;VBOR set to 1.90 V nominal
    Config WDTEN = OFF ;Watch dog timer is always disabled. SWDTEN has no effect.
    Config WDTPS = 32768 ;1:32768
    Config CCP2MX = PORTC1 ;CCP2 input/output is multiplexed with RC1
    Config PBADEN = OFF ;PORTB<5:0> pins are configured as digital I/O on Reset
    Config CCP3MX = PORTE0 ;P3A/CCP3 input/output is mulitplexed with RE0
    Config HFOFST = On ;HFINTOSC output and ready status are not delayed by the oscillator stable status
    Config T3CMX = PORTC0 ;T3CKI is on RC0
    Config P2BMX = PORTD2 ;P2B is on RD2
    Config MCLRE = EXTMCLR ;MCLR pin enabled, RE3 input pin disabled
    Config STVREN = On ;Stack full/underflow will cause Reset
    Config LVP = OFF ;Single-Supply ICSP enabled if MCLRE is also 1
    Config XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Config Debug = OFF ;Disabled
    Config CP0 = OFF ;Block 0 (000800-001FFFh) not code-protected
    Config CP1 = OFF ;Block 1 (002000-003FFFh) not code-protected
    Config CP2 = OFF ;Block 2 (004000-005FFFh) not code-protected
    Config CP3 = OFF ;Block 3 (006000-007FFFh) not code-protected
    Config CPB = OFF ;Boot block (000000-0007FFh) not code-protected
    Config CPD = OFF ;Data EEPROM not code-protected
    Config WRT0 = OFF ;Block 0 (000800-001FFFh) not write-protected
    Config WRT1 = OFF ;Block 1 (002000-003FFFh) not write-protected
    Config WRT2 = OFF ;Block 2 (004000-005FFFh) not write-protected
    Config WRT3 = OFF ;Block 3 (006000-007FFFh) not write-protected
    Config WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
    Config WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
    Config WRTD = OFF ;Data EEPROM not write-protected
    Config EBTR0 = OFF ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
    Config EBTR1 = OFF ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
    Config EBTR2 = OFF ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
    Config EBTR3 = OFF ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
    Config EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    Endasm-
    Declare Reminders On

    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
    '
    '
    $ifndef __FONT__
    $define __FONT__

    GoTo _OverFontTable_
    ' Font CDATA table
    ' Copy and paste this table into your own program
    ' if an internal font is required.
    Font:- CData $00,$00,$00,$00,$00,$00,_ 'Graphic character 0
    $FF,$FF,$FF,$FF,$FF,$FF,_ 'Graphic character 1
    $07,$07,$07,$00,$00,$00,_ 'Graphic character 2
    $00,$00,$00,$07,$07,$07,_ 'Graphic character 3
    $E0,$E0,$E0,$00,$00,$00,_ 'Graphic character 4
    $00,$00,$00,$E0,$E0,$E0,_ 'Graphic character 5
    $FF,$FF,$FF,$00,$00,$00,_ 'Graphic character 6
    $00,$00,$00,$FF,$FF,$FF,_ 'Graphic character 7
    $07,$07,$07,$07,$07,$07,_ 'Graphic character 8
    $E0,$E0,$E0,$E0,$E0,$E0,_ 'Graphic character 9
    $E0,$E0,$E0,$07,$07,$07,_ 'Graphic character 10
    $07,$07,$07,$E0,$E0,$E0,_ 'Graphic character 11
    $FF,$FF,$FF,$E0,$E0,$E0,_ 'Graphic character 12
    $E0,$E0,$E0,$FF,$FF,$FF,_ 'Graphic character 13
    $07,$07,$07,$FF,$FF,$FF,_ 'Graphic character 14
    $FF,$FF,$FF,$07,$07,$07,_ 'Graphic character 15
    $55,$AA,$55,$AA,$55,$AA,_ 'Graphic character 16
    $AA,$55,$AA,$55,$AA,$55,_ 'Graphic character 17
    $01,$01,$01,$01,$01,$01,_ 'Graphic character 18
    $80,$80,$80,$80,$80,$80,_ 'Graphic character 19
    $FF,$00,$00,$00,$00,$00,_ 'Graphic character 20
    $00,$00,$00,$00,$00,$FF,_ 'Graphic character 21
    $FF,$01,$01,$01,$01,$01,_ 'Graphic character 22
    $01,$01,$01,$01,$01,$FF,_ 'Graphic character 23
    $FF,$80,$80,$80,$80,$80,_ 'Graphic character 24
    $80,$80,$80,$80,$80,$FF,_ 'Graphic character 25
    $00,$00,$00,$00,$F0,$F0,_ 'User defined character 26
    $00,$00,$00,$00,$0F,$0F,_ 'User defined character 27
    $00,$00,$00,$00,$00,$00,_ 'User defined character 28
    $00,$00,$00,$00,$00,$00,_ 'User defined character 29
    $00,$00,$00,$00,$00,$00,_ 'User defined character 30
    $00,$00,$00,$00,$00,$00,_ 'User defined character 31
    $00,$00,$00,$00,$00,$00,_ '32 - - 20
    $00,$00,$4F,$00,$00,$00,_ '33 - ! - 21
    $00,$07,$00,$07,$00,$00,_ '34 - " - 22
    $14,$7F,$14,$7F,$14,$00,_ '35 - # - 23
    $24,$2A,$7F,$2A,$12,$00,_ '36 - $ - 24
    $23,$13,$08,$64,$62,$00,_ '37 - % - 25
    $36,$49,$55,$22,$50,$00,_ '38 - & - 26
    $00,$05,$03,$00,$00,$00,_ '39 - ' - 27
    $1C,$22,$41,$00,$00,$00,_ '40 - ( - 28
    $00,$00,$41,$22,$1C,$00,_ '41 - ) - 29
    $14,$08,$3E,$08,$14,$00,_ '42 - * - 2A
    $08,$08,$3E,$08,$08,$00,_ '43 - + - 2B
    $00,$50,$30,$00,$00,$00,_ '44 - , - 2C
    $08,$08,$08,$08,$08,$00,_ '45 - - - 2D
    $00,$60,$60,$00,$00,$00,_ '46 - . - 2E
    $20,$10,$08,$04,$02,$00,_ '47 - / - 2F
    $3E,$51,$49,$45,$3E,$00,_ '48 - 0 - 30
    $00,$42,$7F,$40,$00,$00,_ '49 - 1 - 31
    $42,$61,$51,$49,$46,$00,_ '50 - 2 - 32
    $21,$41,$45,$4B,$31,$00,_ '51 - 3 - 33
    $18,$14,$12,$7F,$10,$00,_ '52 - 4 - 34
    $27,$45,$45,$45,$39,$00,_ '53 - 5 - 35
    $3C,$4A,$49,$49,$30,$00,_ '54 - 6 - 36
    $01,$71,$09,$05,$03,$00,_ '55 - 7 - 37
    $36,$49,$49,$49,$36,$00,_ '56 - 8 - 38
    $06,$49,$49,$49,$3E,$00,_ '57 - 9 - 39
    $00,$36,$36,$00,$00,$00,_ '58 - : - 3A
    $00,$56,$36,$00,$00,$00,_ '59 - ; - 3B
    $08,$14,$22,$41,$00,$00,_ '60 - < - 3C
    $14,$14,$14,$14,$14,$00,_ '61 - = - 3D
    $00,$41,$22,$14,$08,$00,_ '62 - > - 3E
    $02,$01,$51,$09,$06,$00,_ '63 - ? - 3F
    $32,$49,$79,$41,$3E,$00,_ '64 - @ - 40
    $7E,$11,$11,$11,$7E,$00,_ '65 - A - 41
    $7F,$49,$49,$49,$36,$00,_ '66 - B - 42
    $3E,$41,$41,$41,$22,$00,_ '67 - C - 43
    $7F,$41,$41,$22,$1C,$00,_ '68 - D - 44
    $7F,$49,$49,$49,$41,$00,_ '69 - E - 45
    $7F,$09,$09,$09,$01,$00,_ '70 - F - 46
    $3E,$41,$49,$49,$7A,$00,_ '71 - G - 47
    $7F,$08,$08,$08,$7F,$00,_ '72 - H - 48
    $00,$41,$7F,$41,$00,$00,_ '73 - I - 49
    $20,$40,$41,$3F,$01,$00,_ '74 - J - 4A
    $7F,$08,$14,$22,$41,$00,_ '75 - K - 4B
    $7F,$40,$40,$40,$40,$00,_ '76 - L - 4C
    $7F,$02,$0C,$02,$7F,$00,_ '77 - M - 4D
    $7F,$04,$08,$10,$7F,$00,_ '78 - N - 4E
    $3E,$41,$41,$41,$3E,$00,_ '79 - O - 4F
    $7F,$09,$09,$09,$06,$00,_ '80 - P - 50
    $3E,$41,$51,$21,$5E,$00,_ '81 - Q - 51
    $7F,$09,$19,$29,$46,$00,_ '82 - R - 52
    $46,$49,$49,$49,$31,$00,_ '83 - S - 53
    $01,$01,$7F,$01,$01,$00,_ '84 - T - 54
    $3F,$40,$40,$40,$3F,$00,_ '85 - U - 55
    $1F,$20,$40,$20,$1F,$00,_ '86 - V - 56
    $3F,$40,$38,$40,$3F,$00,_ '87 - W - 57
    $63,$14,$08,$14,$63,$00,_ '88 - X - 58
    $07,$08,$70,$08,$07,$00,_ '89 - Y - 59
    $61,$51,$49,$45,$43,$00,_ '90 - Z - 5A
    $7F,$41,$41,$00,$00,$00,_ '91 - [ - 5B
    $02,$04,$08,$10,$20,$00,_ '92 - \ - 5C
    $00,$00,$41,$41,$7F,$00,_ '93 - ] - 5D
    $04,$02,$01,$02,$04,$00,_ '94 - ^ - 5E
    $40,$40,$40,$40,$40,$00,_ '95 - _ - 5F
    $00,$01,$02,$04,$00,$00,_ '96 - ` - 60
    $20,$54,$54,$54,$78,$00,_ '97 - a - 61
    $7F,$48,$44,$44,$38,$00,_ '98 - b - 62
    $38,$44,$44,$44,$20,$00,_ '99 - c - 63
    $38,$44,$44,$48,$7F,$00,_ '100 d - 64
    $38,$54,$54,$54,$18,$00,_ '101 e - 65
    $08,$7E,$09,$01,$02,$00,_ '102 f - 66
    $0C,$52,$52,$52,$3E,$00,_ '103 g - 67
    $7F,$08,$04,$04,$78,$00,_ '104 h - 68
    $00,$44,$7D,$40,$00,$00,_ '105 i - 69
    $00,$20,$40,$44,$3D,$00,_ '106 j - 6A
    $7F,$10,$28,$44,$00,$00,_ '107 k - 6B
    $00,$41,$7F,$40,$00,$00,_ '108 l - 6C
    $7C,$04,$18,$04,$78,$00,_ '109 m - 6D
    $7C,$08,$04,$04,$78,$00,_ '110 n - 6E
    $38,$44,$44,$44,$38,$00,_ '111 o - 6F
    $7C,$14,$14,$14,$08,$00,_ '112 p - 70
    $08,$14,$14,$18,$7C,$00,_ '113 q - 71
    $7C,$08,$04,$04,$08,$00,_ '114 r - 72
    $48,$54,$54,$54,$20,$00,_ '115 s - 73
    $04,$3F,$44,$40,$20,$00,_ '116 t - 74
    $3C,$40,$40,$20,$7C,$00,_ '117 u - 75
    $1C,$20,$40,$20,$1C,$00,_ '118 v - 76
    $3C,$40,$30,$40,$3C,$00,_ '119 w - 77
    $44,$28,$10,$28,$44,$00,_ '120 x - 78
    $0C,$50,$50,$50,$3C,$00,_ '121 y - 79
    $44,$64,$54,$4C,$44,$00,_ '122 z - 7A
    $08,$36,$41,$00,$00,$00,_ '123 { - 7B
    $00,$00,$7F,$00,$00,$00,_ '124 | - 7C
    $00,$00,$41,$36,$08,$00,_ '125 } - 7D
    $00,$08,$04,$08,$04,$00 '126 ~ - 7E
    _OverFontTable_:
    $endif

    ;-------------------------------------------------------------------------------


    '------------------------- Port Assignments --------------------------------

    ' PORTD Graphic 8 bit Data Line
    ' PORTA.1 LCD Data Line - Bit 5
    ' PORTA.2 LCD Data Line - Bit 6
    ' PORTA.3 LCD Data Line - Bit 7
    ' PORTA.4 LCD Data Line - Register Select
    ' PORTA.5 Not used
    ' PORTB.0 CS1 - KS108 Chip select 1
    ' PORTB.1 CS2 - KS108 Chip select 2
    ' PORTB.2 RS - KS108 Register select Line
    ' PORTB.3 RW - KS108 Read/Write Line
    ' PORTB.4 EN - KS108 Enable Line
    ' PORTB.5 RST - KS108 Reset Line
    ' PORTB.6 Not used
    ' PORTB.7 Not used
    ' PORTC.2 Beeper
    ' PortE.1 1 Wire IO


    '--------------------------- Setup DEFINE's ----------------------------------

    Declare Xtal 4 ' 4 Mhz
    '
    '------------------------ Port Initialization -------------------------------

    OSCCON = %01010110 ' Internal 4 Mhz Osc
    CCP1CON = %00000000 ' Disable CCP Module
    TXSTA.5 = 0 ' Disable AUSART Tx
    RCSTA.7 = 0 ' Disable Serial Port
    CM1CON0.7 = 0 ' Turn off all comparator 1
    CM2CON0.7 = 0 ' Turn off all comparator 2
    ADCON0 = 0 ' ADC's disabled
    ADCON1 = 0 '
    ADCON2 = 0 '
    ANSELA = 0 ' Set to digital inputs
    ANSELB = 0 ' "
    ANSELC = 0 ' "
    ANSELD = 0 ' "
    ANSELE = 0 '
    TRISA = %00000000 ' PortA all outputs
    TRISB = %00000000 '
    TRISC = %11111111 '
    TRISD = %00000000 '
    TRISE = %00000000 '
    PORTA = 0 '
    PORTB = 0 '
    PORTC = 0 '
    PORTD = 0 '
    PORTE = 0 '

    'Samsung KS0108 Graphic LCD specific Declares.

    Declare LCD_Type = Graphic ' KS108 controller
    Declare LCD_DTPort = PORTD ' Assign the port that will output the 8-bit data to the graphic LCD.
    Declare LCD_CS1Pin = PORTB.0 ' Assigns the Port and Pin that the graphic LCD's CS1 line will attach to.
    Declare LCD_CS2Pin = PORTB.1 ' Assigns the Port and Pin that the graphic LCD's CS2 line will attach to.
    Declare LCD_RSPin = PORTB.2 ' Assigns the Port And Pin that the graphic LCD's RS line will attach to.
    Declare LCD_RWPin = PORTB.3 ' Assigns the Port and Pin that the graphic LCD's RW line will attach to.
    Declare LCD_ENPin = PORTB.4 ' Assigns the Port And Pin that the graphic LCD's EN line will attach to.
    Declare LCD_RSTPin = PORTB.5 ' Assigns the Port And Pin that the graphic LCD's RST line will attach to.
    Declare LCD_DTPin = PORTD.0 ' Used for 8-line interface.
    Declare Internal_Font On ' On - Off, 1 or 0
    '
    '------------------------ LCD characteristics --------------------------------
    '
    Declare LCD_X_Res = 128 ' LCD’s X Resolution
    Declare LCD_Y_Res = 64 ' LCD’s Y Resolution
    Declare LCD_Font_Width = 8 ' The width of the LCD’s font


    '----------------------------- Port Aliases ---------------------------------

    Symbol Iwire = PORTE.1
    PORTB.5 = 1
    Symbol Beep = PORTC.2

    '---------------------- Miscellaneous Variables ------------------------------

    Dim ID[8] As Byte '

    '
    'Main Program
    '-----------------
    Ident:
    Cls

    Print At 0,3, "Insert Ibutton" '
    DelayMS 1000 '
    OWrite Iwire, 1, [$33] ' Read ROM Comand
    ORead Iwire, 2, [Str ID\8] '
    '
    If ID[0] = $FF Then ' If no ibutton then beep
    FreqOut Beep, 1000, 500 ' 500hz, 1 sec
    GoTo Ident ' loop
    EndIf
    '
    Print At 2,0, "CRC = ", Hex ID[7]'
    DelayMS 500 '
    '
    Print At 3,0, " SN = ",_ '
    Hex ID[6], Hex ID[5], Hex ID[4],_'
    Hex ID[3], Hex ID[2], Hex ID[1] '
    DelayMS 500 '
    '
    Print At 4,0, " FC = ",_ '
    Hex ID[0], "H" '
    DelayMS 500 '
    '
    If ID[0] = $01 Then '
    Print At 5,0, "DS1990, S/N Ibutton"'
    DelayMS 2000 '
    EndIf '

    If ID[0] = $0C Then '
    Print At 5,0, "DS1996, 64K" '
    DelayMS 2000 '
    EndIf '
    '
    If ID[0] = $23 Then '
    Print At 5,0, "DS1973, 4K" '
    DelayMS 2000 '
    EndIf '
    '
    GoTo Ident '
    '
    End
    [/PHP]