Cbstartbook

221

Transcript of Cbstartbook

  • Cont tsen

  • Cont tsen

  • Cont tsen

  • 66

  • 477

    CUBLOC

  • 88

  • 499

    CUBLOC

  • 98 ab 3c 12 03 cc

    75 32 95 33 A2 00

    1010

  • CUBLOC

    1111

    I/O : 16

    FLASH : 80K

    RAM : 3K

    I/O : 49

    FLASH : 80K

    RAM : 3K

    I/O : 91

    FLASH : 80K

    RAM : 28K

    CB220

    CB280

    CB290

  • 1212

    Cubloc

    Studio

  • LAB.1

    1414

  • CUBLOC

    Cubloc

    Studio

    1515

    .

    !

    LAB.1

  • LAB.1

    1616

  • CUBLOC

    1717

    LAB.1

    +-

  • 1818

    LAB.1

  • CUBLOC

    1919

    LAB.1

  • Const Device = CB280

    Do

    High 0

    Delay 200

    Low 0

    Delay 200

    Loop

    Const Device

    Do, Loop

    2020

    LAB.1

  • CUBLOC

    High

    Low

    SOUT

    SIN

    ATN

    VSS

    P0

    P1

    P2

    P3

    P4

    P5

    P6

    P7

    P8

    P9

    P10

    P11

    TX1

    RX1

    AVDD

    N/C

    P24

    P25

    P26

    P27

    P47

    P46

    P45

    P44

    P43

    P42

    P41

    P40

    VDD

    VSS

    RES

    N/C

    P16

    P17

    P18

    P19

    P20

    P21

    P22

    P23

    P15

    P14

    P13

    P12

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    TTLTX1

    TTLRX1

    AVREF

    P48

    P31

    P30

    P29

    P28

    P32

    P33

    P34

    P35

    P36

    P37

    P38

    P39

    Delay

    2121

    LAB.1

    Vdd Vdd

    Vss Vss

  • CUBLOC

    2323

    220V

    9V

    5V

    LAB.1

    7805

    7805

    3V

    1.5V

    1.5V

    7805

    7805

  • 2424

    LAB.1

    330

    0 1 2 3 4 5 6 7

    LED

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

  • CUBLOC

    2525

    1

    2

    3

    4

    LAB.1

  • 2626

    I/O 0

    I/O 1

    CB280

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    LAB.2

  • CUBLOC

    2727

    LAB.2

  • 2828

    LAB.2

    1

    1

    2

    2

    3

    3

    41,4

    2,3

    1 2 3

  • CUBLOC

    2929

    MAX232

    CH1

    (BACK)

    JP1 JP2

    RESET

    CB280

    CB220

    GND

    LED

    0 1 2 3 4 5 6 7

    0 1 2 3 4 5 6 7

    0 1 2 3 4 5 6 7

    0 1 2 3

    0 1 2 3 4 5 6 7

    0 1 2 3 4 5 6 70 1 2 3 0 1 2 3 4 5 6 7

    LED

    A/D

    (POT)

    A/D

    (POT)

    TOGGLE

    TOGGLE

    PUSH S/W

    PUSH S/W

    BREAD BOARD

    CB280

    CB220

    CUNET

    ALCD

    CSG

    I/O 8 I/O 9

    JUMPER

    I/O 3

    I/O 4

    PIEZODOWNLOAD

    5V(VDD)

    GND(VSS)

    TTLTX

    (a)

    TTLRX

    TX

    RX

    SOUT

    SIN

    ATN

    VSS

    SS_P0

    (Input_only)SCK_P1

    MOSI_P2

    MISO_P3

    P4

    PWM0_P5

    PWM1_P6

    PWM2_P7

    (CUNET)SCL_P8

    (CUNET)SDA_P9

    P10

    P11

    TX1

    RX1

    AVDD

    N/C

    ADC0_P24

    ADC1_P25

    ADC2_P26

    ADC3_P27

    P47

    P46

    P45

    P44

    P43

    P42

    P41

    P40

    VDD

    VSS

    RES

    N/C

    P16

    P17

    P18

    P19_PWM3

    P20_PWM4_INT0

    P21_PWM5_INT1

    P22_INT2

    P23_INT3

    P15_HCNT0

    P14_HCNT1

    P13

    P12

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    TTLTX1

    TTLRX1

    AVREF

    P48

    P31_ADC7

    P30_ADC6

    P29_ADC5

    P28_ADC4

    P32

    P33

    P34

    P35

    P36

    P37

    P38

    P39

    SOUT

    SIN

    ATN

    VSS

    SS_P0

    (Input only)SCK_P1

    MOSI_P2

    MISO_P3

    P4

    PWM0_P5

    PWM1_P6

    PWM2_P7

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    24

    23

    22

    21

    20

    19

    18

    17

    16

    15

    14

    13

    VIN (5.5V~12Vinput)

    VSS

    RES

    VDD

    P15_HCNT0

    P14_HCNT1

    P13

    P12

    P11_TX(CH1)

    P10_RX(CH1)

    P9_SDA(CUNET)

    P8_SCL(CUNET)

    0

    I/O PORTS

    1

    SO

    UT

    SIN

    AT

    NV

    SS

    2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

    24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

    2 3 4 5

    POWER

    S/W

    DC9V

    INPUT

    (a)

    +-2

    3

    5

    1

    2

    3

    4

    5

    6

    7

    8

    16

    15

    14

    13

    12

    11

    10

    9

    MAX232

    5V

    5V

    0.1uF

    RX

    TX

    TD

    RD

    0.1uF

    0.1uF

    0.1uF

    0.1uF

    LAB.2

  • Const Device = CB280

    Dim I As Integer

    Do

    I = In(1)

    If I =0 Then

    Low 0

    Else

    High 0

    End If

    Loop

    I

    I

    I

    I

    3030

    0 1

    Dim

    Q AQ A&

    LAB.2

  • CUBLOC

    3131

    LAB.2

    1 BYTE1 Nibble

    1 WORD

    DOUBLE WORD

    BYTE

    WORD

    Double WORD

  • II = IN(1)

    If I =0 Then

    Low 0

    Else

    High 0

    End If

    3232

    IFLAB.2

  • CUBLOC

    In( )

    3333

    1

    2

    3

    LAB.2

  • Const Device = CB280

    Dim A1 as Integer

    Dim A2 as Integer

    Dim A3 as Integer

    Dim A4 as Integer

    Dim A5 as Integer

    Dim A6 as Integer

    Dim A7 as Integer

    Dim A8 as Integer

    Dim A9 as Integer

    Dim A10 as Integer

    Dim A11 as Integer

    Const Device = CB280

    Dim A(12) as Integer

    Const Device = CB280

    Dim A(12) as Integer

    Dim B as Integer

    B = 0

    A(0) = 12

    A(B) = 12

    3434

    A(6)

    A(3,6)

    A(3,3,6)

  • 3636

    8 9 10 11 12 13 14 15

    I/O I/O I/O I/O I/O I/O I/O I/O

    CB280

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    LAB.3

  • Const Device = CB280

    Do

    High 8

    Delay 200

    Low 8

    Delay 200

    Loop

    Const Device = CB280

    Do

    Byteout 1,255

    Delay 200

    Byteout 1,0

    Delay 200

    Loop

    Const Device = CB280

    Do

    Byteout 1,&HF0

    Delay 200

    Byteout 1,&H0F

    Delay 200

    Loop

    Const Device = CB280

    Do

    High 8

    High 9

    High 10

    High 11

    High 12

    High 13

    High 14

    High 15

    Delay 200

    Low 8

    Low 9

    Low 10

    Low 11

    Low 12

    Low 13

    Low 14

    Low 15

    Delay 200

    Loop 3737

    CUBLOC

    LAB.3

  • 3838

    LAB.3

  • Const Device = CB280

    Dim I As Byte

    Do

    I=I+1

    Byteout 1,I

    Delay 200

    Loop

    SOUT

    SIN

    ATN

    VSS

    P0

    P1

    P2

    P3

    P4

    P5

    P6

    P7

    P8

    P9

    P10

    P11

    TX1

    RX1

    AVDD

    N/C

    P24

    P25

    P26

    P27

    P47

    P46

    P45

    P44

    P43

    P42

    P41

    P40

    VDD

    VSS

    RES

    N/C

    P16

    P17

    P18

    P19

    P20

    P21

    P22

    P23

    P15

    P14

    P13

    P12

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    TTLTX1

    TTLRX1

    AVREF

    P48

    P31

    P30

    P29

    P28

    P32

    P33

    P34

    P35

    P36

    P37

    P38

    P39

    0 2

    3

    45

    1

    I

    I

    I

    3939

    CUBLOC

    Byteout

    LAB.3

  • Const Device = CB280

    Dim I As Byte

    Do

    I=I+1

    Byteout 1,I

    Delay 200

    Loop

    Debug Dec I,CR

    Const Device = CB280

    Dim I As Byte

    Do

    I=I+1

    Byteout 1,I

    Delay 200

    Loop

    Debug Dec? I,CR

    4040

    Debug

    Debug Dec A

    Debug Hex A

    Debug "Result :",Dec A

    Debug Dec5 A

    Debug Hex8 A

    Debug Dec ? A

    Debug Float A

    Debug Clr

    Debug Goxy,4,3

    LAB.3

  • Const Device = CB280

    Dim I As Integer, B as Integer

    Delay 500

    A = 5

    B = 300

    A = A * B

    Debug Dec A,CR

    4141

    CUBLOC

    1 1 0 0 1 1 0 0

    1 1 0 0 1 1 0 0

    1 0 0 1 1 0 0 0

    0 1 1 0 0 1 1 0

    LAB.3

  • IConst Device = CB280

    Do

    Byteout 1,1

    Delay 200

    Byteout 1,2

    Delay 200

    Byteout 1,4

    Delay 200

    Byteout 1,8

    Delay 200

    Byteout 1,&H10

    Delay 200

    Byteout 1,&H20

    Delay 200

    Byteout 1,&H40

    Delay 200

    Byteout 1,&H80

    Delay 200

    Loop

    Const Device = CB280

    Dim I As Byte

    Dim J As Byte

    Do

    J = 1

    For I =0 To 7

    Byteout 1,J

    J = J

  • 4343

    CUBLOC

    For, Next

    Dim A as Long

    For A =10 TO 0 Step -1

    Debug Dec A,cr

    Next

    Dim K as Byte

    For K = 0 to 300

    Debug Dec K,cr

    Next

    1

    2

    3

    LAB.3

  • Const Device = CB280

    Dim A as Integer

    Delay 500

    For A=1 to 10

    Debug Dec A,cr

    Next

    Const Device = CB280

    Dim A As Integer

    Delay 500

    For A=1 To 10

    Debug Dec A,cr

    If a=8 Then Exit For

    Next

    Const Device = CB280

    Dim A as Integer

    Delay 500

    For A=1 to 10 Step 2

    Debug Dec A,cr

    Next

    4444

    Const Device = CB280

    Dim A As Integer

    Delay 500

    For A=1 To 9

    Debug "6 x ",Dec A," = ", Dec 6 * A,cr

    Next

  • 4545

    1 1

    1

    22

    2

    3

    45

    6

    7

    1 1

    1

  • 4646

    8 9 10 11 12 13 14 15

    I/O I/O I/O I/O I/O I/O I/O I/O

    I/O 5

    CB280

    PIEZO

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    LAB.4

  • CUBLOC

    Const

    4747

    LAB.4

  • Const Device = CB280

    Low 5

    Do

    Reverse 5

    Delay 1

    Loop

    4848

    LAB.4

    Reverse

    Low 5

    Reverse 5

  • Const Device = CB280

    Low 5

    Pwm 0,200,5000

    CUBLOC

    PWM

    4949

    PWM 0, 200, 1024

    LAB.4

  • 5050

    Pwmoff

    Freqout

    Low 5

    Pwm 0, 50, 100

    Delay 2000

    Pwmoff 0

    Freqout 0, 5236

    LAB.4

  • CUBLOC

    Const Device = CB280

    Const SoundCh = 0

    Dim A As Byte

    Low 5

    Do

    A = Bytein(1)

    Select Case A

    Case 1

    Freqout SoundCh,4403 '

    Case 2

    Freqout SoundCh,3923 '

    Case 4

    Freqout SoundCh,3495 '

    Case 8

    Freqout SoundCh,3299 '

    Case &h10

    Freqout SoundCh,2939 '

    Case &h20

    Freqout SoundCh,2618 '

    Case &h40

    Freqout SoundCh,2333 '

    Case &h80

    Freqout SoundCh,2202 '

    Case Else

    Pwmoff 0

    End Select

    Loop

    0

    0

    0

    0

    0

    0

    0

    1

    0

    0

    0

    0

    0

    0

    1

    0

    0

    0

    0

    0

    0

    1

    0

    0

    0

    0

    0

    0

    1

    0

    0

    0

    0

    0

    0

    1

    0

    0

    0

    0

    0

    0

    1

    0

    0

    0

    0

    0

    0

    1

    0

    0

    0

    0

    0

    0

    1

    0

    0

    0

    0

    0

    0

    0

    = 1

    = 2

    = 4

    = 8

    = &H10

    = &H20

    = &H40

    = &H80 5151

    Select, Case

    Select Case K

    4

    1

    5

    2

    00

    3

    else

    4

    End Select

    Case Is < 10

    R = 0

    Case Is < 0

    R =

    Case Is < 0

    R =

    Case Is < 1

    R =

    Case

    R =

    LAB.4

  • Const Device = CB280

    Const SoundCh = 0

    Dim A As Byte

    Low 5

    Do

    A = Bytein(1)

    Select Case A

    Case 1

    Case 2

    Freqout SoundCh,3923 '

    Case 4

    Freqout SoundCh,3495 '

    Case 8

    Freqout SoundCh,3299 '

    Case &h10

    Freqout SoundCh,2939 '

    Case &h20

    Freqout SoundCh,2618 '

    Case &h40

    Freqout SoundCh,2333 '

    Case &h80

    Freqout SoundCh,2202 '

    Case Else

    Pwmoff 0

    End Select

    Loop

    Freqout SoundCh,4403 '

    Delay 200

    Freqout SoundCh,3495 '

    Delay 200

    Freqout SoundCh,2202 '

    Delay 200

    Const Device = CB280

    Const SoundCh = 0

    Const = 4403

    Const = 3923

    Const = 3495

    Const = 3299

    Const = 2939

    Const = 2618

    Const = 2333

    Const H = 2202

    Dim A As Byte

    Low 5

    Do

    A = Bytein(1)

    Select Case A

    Case 1

    Freqout SoundCh,

    Case 2

    Freqout SoundCh,

    Case 4

    Freqout SoundCh,

    Case 8

    Freqout SoundCh,

    Case &h10

    Freqout SoundCh,

    Case &h20

    Freqout SoundCh,

    Case &h40

    Freqout SoundCh,

    Case &h80

    Freqout SoundCh,H

    Case Else

    Pwmoff 0

    End Select

    Loop5252

    Bytein

    LAB.4

  • CUBLOC

    Const Device = CB280

    Const SoundCh = 0

    Const = 4403

    Const = 3923

    Const = 3495

    Const = 3299

    Const = 2939

    Const = 2618

    Const = 2333

    Const H = 2202

    #define SoundOut Freqout SoundCh,

    #define Wait1 Delay 300

    #define Wait2 Delay 700

    #define Wait0 Delay 50

    Low 5

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait2

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait2

    Pwmoff 0

    Wait1

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait2

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait1

    Pwmoff 0

    Wait0

    SoundOut

    Wait2

    Pwmoff 0

    5353

    LAB.4

  • Const Device = CB280

    Const SoundCh = 0

    Const = 4403

    Const = 3923

    Const = 3495

    Const = 3299

    Const = 2939

    Const = 2618

    Const = 2333

    Const H = 2202

    Const W1 = 300

    Const W2 = 700

    Low 5

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W2

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W2

    Delay w2

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W2

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W1

    SoundOut ,W2

    End

    Sub SoundOut(Fr As Integer, Wt As Integer)

    Freqout soundch,Fr

    Delay wt

    Pwmoff 0

    Delay 50

    End Sub

    5454

    #define

    #define Playsound Freqout 0, 4938

    LAB.4

  • CUBLOC

    5555

    Sub, Endsub

    SoundOut W2

    End

    Sub SoundOut(Fr As Integer, Wt As Integer)

    Freqout soundch,Fr

    Delay wt

    Pwmoff 0

    Delay 50

    End Sub

    Sub DelayLong()

    Delay 5000

    End Sub

    1

    2

    3

    LAB.4

  • Const Device = CB280

    Dim A as Integer

    Delay 500p

    A = AplusB( 10, 5)

    Debug Dec A

    End

    Function ApulsB( PA As Integer, PB As Integer)

    AplusB = PA + PB

    End Function

    Const Device = CB280

    Dim A as Integer

    Delay 500p

    A = AplusB( 10, 5)

    Debug Dec A

    End

    Function ApulsB( PA As Integer, PB As Integer)

    Dim C As Integer

    C = PA + PB

    ApulsB = C

    End Function

    Function ApulsB( PA As Integer, PB As Integer) as Integer

    AplusB = PA + PB

    End Function

    5656

  • 5757

  • 5858

    I/O 24 I/O 25 I/O 26 I/O 27

    CB280

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    0 1 2 3

    A/D

    (POT)

    LAB.5

  • CUBLOC

    5959

    LAB.5

  • 6060

    LAB.5

    3

    2

    1

    5V

    GND

    12

    3

  • TAdin

    I = Tadin(0)

    Const Device = CB280

    Dim I As Integer

    Do

    I = Adin(0)

    Debug Dec I,CR

    Delay 200

    Loop

    CUBLOC

    6161

    Adin

    Const Device = CB280

    Dim A as Integer

    Input 24

    A = Adin(0)

    Const Device = CB280

    Dim A as Integer

    Input 24

    A = TAdin(0)

    LAB.5

  • Const Device = CB280

    Dim I As Integer

    Do

    I = Adin(0)

    Debug goxy,3,2

    Debug Dec5 I,CR

    I = Adin(1)

    Debug goxy,13,2

    Debug Dec5 I,CR

    I = Adin(2)

    Debug goxy,23,2

    Debug Dec5 I,CR

    I = Adin(3)

    Debug goxy,33,2

    Debug Dec5 I,CR

    Delay 200

    Loop

    6262

    LAB.5

  • Const Device = CB280

    Dim I As Integer

    Low 5

    Do

    I = Tadin(0)

    Pwm 0,I,1024

    Delay 200

    Loop

    CUBLOC

    6363

    LAB.5

    101010101

    CB280

    P5

    330ohm

    0.01uF

    D/A

    Output

  • 6464

    LAB.5

  • CUBLOC

    1

    2

    LAB.5

    6565

  • Do

    Byteout 1,A

    Loop

    Debug "END"

    Const Device = CB280

    Set Debug off

    6666

  • 6767

    CUBLOC

  • 6868

  • 6969

    CUBLOC

  • CUBLOC

    0

    1

    2

    3

    4

    5

    6

    7

    0 4 8 12

    1 5 9 13

    2 6 10 14

    3 7 11 15

    Const Device = CB280

    Dim A As Integer

    Do

    A = Keypad(0)

    Debug goxy,10,2

    Debug Dec4 a

    Delay 100

    Loop

    7171

    LAB.6

  • 7272

    Keypad

    EKeypad

    0

    1

    2

    3

    0

    1

    2

    3

    4

    5

    6

    7

    4

    5

    6

    7

    0

    0

    4

    4

    8

    8

    12

    1

    1

    5

    5

    9

    9

    13

    2

    2

    6

    6

    10

    10

    14

    3 7 11 15

    A=Ekeypad(0,1)

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    LAB.6

  • 11

    2

    2

    3

    3

    4

    4

    5

    5

    6

    6

    7

    7

    8

    8

    9

    9

    0

    0

    Enter

    Enter

    ScanCode = Keypad(0)

    If ScanCode = 0 then A = 1

    If ScanCode = 1 then A = 4

    If ScanCode = 2 then A = 7

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    0

    1

    1

    4

    2

    7

    3

    11

    4

    2

    5

    5

    6

    8

    7

    0

    8

    3

    9

    6

    10

    9

    11

    12

    12

    13

    13

    14

    14

    15

    15

    16

    Const Device = CB280

    Const Byte Ktbl = (1,4,7,11,2,5,8,0,3,6,9,12,13,14,15,16)

    Dim A As Integer

    Dim K As Integer

    Do

    A = Keypad(0)

    If a = 255 Then

    k = 255

    Else

    k = Ktbl(a)

    End If

    Debug goxy,10,2

    Debug Dec4 k

    Delay 100

    Loop

    7373

    CUBLOC

    LAB.6

  • Const Array

    Dim A as Long, B as Long

    Const Byte data1 = (31,25,102,34,1)

    A = date1 (0)

    B = data1(1)

    Const Byte data2 = (" CUBLOC SYSTEM")

    A = Data2(0)

    Dim A as Long, B as Long

    Const Integer data3 = (1234, 342,1, 12000, 21)

    Const Long data4 = (1238238, -128328, -1, 0, 12323)

    Const Single Data5 = (32.1, 3.14, 0.12)

    Const String * 6 data6 = ("COMFILE", "BASIC", "ERROR")

    7474

    LAB.6

  • Const Device = CB280

    Const Byte Ktbl = (1,4,7,11,2,5,8,0,3,6,9,12,13,14,15,16)

    Dim A As Integer

    Dim K As Integer

    Dim Res As Long

    Dim M As Long

    Ramclear

    Do

    A = Keypad(0)

    If A < 10 Then

    k = Ktbl(A)

    M = M

  • 7676

    Ramclear

    Bcd2bin

    3 4 5 1

    0 D 7 B

    0 0 0 0 1 1 0 1 0 1 1 1 1 0 1 1

    3 4 5 1

    3 4 5 1

    0 0 1 1 0 1 0 0 0 1 0 1 0 0 0 1

    1

    2

    3

    LAB.6

  • 7777

  • 7878

    I/O 15

    CB280

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    LAB.7

    CB280

    SOUT

    SIN

    ATN

    VSS

    SS_P0

    (Input_only)SCK_P1

    MOSI_P2

    MISO_P3

    P4

    PWM0_P5

    PWM1_P6

    PWM2_P7

    (CUNET)SCL_P8

    (CUNET)SDA_P9

    P10

    P11

    TX1

    RX1

    AVDD

    N/C

    ADC0_P24

    ADC1_P25

    ADC2_P26

    ADC3_P27

    P47

    P46

    P45

    P44

    P43

    P42

    P41

    P40

    VDD

    VSS

    RES

    N/C

    P16

    P17

    P18

    P19_PWM3

    P20_PWM4_INT0

    P21_PWM5_INT1

    P22_INT2

    P23_INT3

    P15_HCNT0

    P14_HCNT1

    P13

    P12

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    TTLTX1

    TTLRX1

    AVREF

    P48

    P31_ADC7

    P30_ADC6

    P29_ADC5

    P28_ADC4

    P32

    P33

    P34

    P35

    P36

    P37

    P38

    P39

  • Const Device = CB280

    Dim A As Integer

    Input 15

    Do

    A = Count(1)

    Debug goxy,10,2

    Debug dec5 A

    Delay 100

    Loop

    7979

    CUBLOC

    LAB.7

  • 8080

    LAB.7

  • CUBLOC

    Count

    8181

    LAB.7

  • Const Device = CB280

    Dim A As Integer

    Input 15

    Low 5

    Freqout 0,2000

    Low 0

    On Timer(100) Gosub GetFreq

    Do

    Loop

    GetFreq:

    A = Count(1)

    Debug goxy,10,2

    Debug dec5 A

    Countreset(1)

    Reverse 0

    Return

    8282

    On Timer

    LAB.7

  • Const Device = CB280

    DelayLong

    Gosub ABC

    Do

    Loop

    ABC:

    Debug "Done"

    Return

    End

    Sub DelayLong()

    Delay 500

    End Sub 8383

    CUBLOC

    Gosub, Return

    Const Device = CB280

    Delay 500

    Gosub ABC

    Do

    Loop

    ABC:

    Debug "Done"

    Return

    LAB.7

  • 8484

    LAB.7

    MAIN PROGRAM

    INTERRUPT

    ROUTINE

  • SOUT

    SIN

    ATN

    VSS

    SS-P0

    SCK-P1

    MOSI-P2

    MISO-P3

    P4

    PWM0-P5

    PWM1-P6

    PWM2-P7

    CUNET_SDL-P8

    CUNET_SDA-P9

    P10

    P11

    TX1

    RX1

    AVDD

    N/C

    AD0-P24

    AD1-P25

    AD2-P26

    AD3-P27

    P47

    P46

    P45

    P44

    P43

    P42

    P41

    P40

    VDD

    VSS

    RES

    N/C

    P16

    P17

    P18

    P19-PWM3

    P20-PWM4-INT0

    P21-PWM5-INT1

    P22-INT2

    P23-INT3

    P15-HCOUNT1

    P14-HCOUNT0

    P13

    P12

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    TTLTX1

    TTLRX1

    AVREF

    P48

    P31-AD7

    P30-AD6

    P29-AD5

    P28-AD4

    P32

    P33

    P34

    P35

    P36

    P37

    P38

    P39

    Const Device = CB280

    Dim R as Integer

    Set Count0 on

    R = Count(0)

    COUNT0

    CUBLOC

    CORE

    PWM0

    PWM1

    PWM2

    8585

    CUBLOC

    LAB.7

  • Set

    Set Count0 On

    Set Onglobal Off

    Set OnInt Off

    Set Ontimer Off

    Set Onrecv Off

    Set OnPad Off

    Set OnLadderInt Off

    Set Ladder On

    Set Debug Off

    Set Display 2,0,1,50

    8686

    1

    LAB.7

  • 8787

  • 8888

    CB280

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    RS232(back)

    CB280

    TX/RX

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    2

    3

    5

    1

    2

    3

    4

    5

    6

    7

    8

    16

    15

    14

    13

    12

    11

    10

    9

    MAX232

    5V

    5V

    0.1uF

    TTLRX1

    TTLTX1

    TD

    RD

    0.1uF

    0.1uF

    0.1uF

    0.1uF

    LAB.8

  • 8989

    CUBLOC

    LAB.8

  • 9090

    Const Device = cb280

    Dim A As Byte

    Opencom 1,115200,3,50,10

    Do

    Do While In(0)=0

    Loop

    Putstr 1,"Hello",cr

    Do While In(0)=1

    Loop

    Loop

    LAB.8

  • Put 1,asc("H"),1

    Put 1,asc("e"),1

    Put 1,asc("l"),1

    Put 1,asc("l"),1

    Put 1,asc("o"),1

    Put 1,13,1

    Put 1,10,1

    Putstr 1,"Hello",cr

    9191

    CUBLOC

    Opencom

    Putstr

    Put

    Putstr 1,"Comfile", Dec A, CR

    LAB.8

  • 9292

    LAB.8

    STA

    RT

    BIT

    0

    BIT

    1

    BIT

    2

    BIT

    3

    BIT

    4

    BIT

    5

    BIT

    6

    BIT

    7

    STO

    P

    STA

    RT

    BIT

    0

    BIT

    1

    BIT

    2

    BIT

    3

    BIT

    4

    BIT

    5

    BIT

    6

    BIT

    7

    STO

    P

    Bit Time(Baudrate)

    STA

    RT

    STA

    RT

    BIT

    0

    BIT

    0

    BIT

    1

    BIT

    1

    BIT

    2

    BIT

    2

    BIT

    3

    BIT

    3

    BIT

    4

    BIT

    4

    BIT

    5

    BIT

    5

    BIT

    6

    BIT

    6

    BIT

    7

    BIT

    7

    STO

    P

    STO

    P

    START STARTSTOP STOP1 1 1 1 11 110 00 0000 0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    TD

    RD

    GND

  • Const Device = cb280

    Dim A As Byte

    Opencom 1,115200,3,50,10

    Do

    A = Get(1,1)

    If Sys(1) = 1 Then

    Put 1,A,1

    End If

    Loop

    9393

    CUBLOC

    LAB.8

  • St1 = Getstr(1,20)

    9494

    Get

    Getstr

    A = Blen(1, 0)

    A = Get(1,2)

    Q AQ A&

    LAB.8

    1

    2

    3

    4

    5

    6

    7

    8

    16

    15

    14

    13

    12

    11

    10

    9

    TTL INPUT

    TTL OUTPUT

    TTL OUTPUT

    TTL INPUT

    RS232C OUTPUT

    RS232C INPUT

    RS232C INPUT

    RS232C OUTPUT

    MAX232

  • Const Device = cb280

    Dim A As Byte

    Opencom 1,115200,3,50,10

    On Recv1 Gosub GOTDATA

    Do

    Do While In(0)=0

    Loop

    Putstr 1,"Cubloc"

    Do While In(0)=1

    Loop

    Loop

    GOTDATA:

    A = Get(1,1)

    Debug A

    Return

    9595

    CUBLOC

    LAB.8

  • On Recv1

    Set Until

    Dim A(5) As Byte

    Opencom 1,19200,3,100,50

    On Recv1 GotData_rtn

    Set Until 1,99, "S"

    Const Device = cb280

    Dim A As Byte

    Dim St1 As String * 6

    Opencom 1,115200,3,50,10

    On Recv1 Gosub GOTDATA

    Do

    Do While In(0)=0

    Loop

    Putstr 1,"Cubloc"

    Do While In(0)=1

    Loop

    Loop

    GOTDATA:

    st1 = Getstr(1,6)

    Debug st1

    Return

    Set Until 1,6

    9696

    LAB.8

  • Const Device = CB280

    Dim A As Byte

    Dim St1 As String * 7

    Opencom 1,115200,3,50,10

    On Recv1 Gosub GOTDATA

    Set Until 1,10,"!"

    Do

    Do While In(0)=0

    Loop

    Putstr 1,"Cubloc!"

    Do While In(0)=1

    Loop

    Loop

    GOTDATA:

    st1 = Getstr(1,7)

    Debug st1

    Return

    CUBLOC

    1

    2

    9797

    LAB.8

  • CB280

    CSG-4S

    GND

    5V

    P3

    P4

    GND

    5V

    SCL

    SDA

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    LAB.9

    9898

  • Const Device = CB280

    Dim B As Integer

    Set I2c 4,3

    B=8

    Do

    Csgdec 0,B

    Delay 100

    Incr B

    Loop

    CUBLOC

    9999

    LAB.9

  • Set I2C

    100100

    Csgdec

    LAB.9

    SCL (Clock)

    SDA (Data)

    Slave

    Address

    "01"

    Slave

    Address

    "02"

    Slave

    Address

    "12"

    Slave

    Address

    "34"

    Slave

    Address

    "127"

    SCL

    SDA

    5V

    5V

    5V

    5V

    SCL

    SDA

  • CUBLOC

    101101

    Q AQ A&

    SCL

    CB28024LC32

    P2

    P3SDA

    A0

    A1

    A2

    LAB.9

    I2C

    RS232

    CB280

    SOUT

    SIN

    ATN

    VSS

    SS_P0

    (Input_only)SCK_P1

    MOSI_P2

    MISO_P3

    P4

    PWM0_P5

    PWM1_P6

    PWM2_P7

    (CUNET)SCL_P8

    (CUNET)SDA_P9

    P10

    P11

    TX1

    RX1

    AVDD

    N/C

    ADC0_P24

    ADC1_P25

    ADC2_P26

    ADC3_P27

    P47

    P46

    P45

    P44

    P43

    P42

    P41

    P40

    VDD

    VSS

    RES

    N/C

    P16

    P17

    P18

    P19_PWM3

    P20_PWM4_INT0

    P21_PWM5_INT1

    P22_INT2

    P23_INT3

    P15_HCNT0

    P14_HCNT1

    P13

    P12

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    TTLTX1

    TTLRX1

    AVREF

    P48

    P31_ADC7

    P30_ADC6

    P29_ADC5

    P28_ADC4

    P32

    P33

    P34

    P35

    P36

    P37

    P38

    P39

    5V5V

    SCL

    SDA

  • Const Device = CB280

    Dim B As Integer

    Set I2c 4,3

    B=0

    Do

    Csgxput 0,0,B

    Delay 100

    Incr b

    Loop

    102102

    Csgxput

    LAB.9

  • 1Const Device = CB280

    Dim B As Integer

    Set I2c 4,3

    B=&H30

    Do

    Csgnput 0,0,B

    Delay 100

    Incr b

    If B>&h3f then B = &h30

    Loop

    CUBLOC

    103103

    Csgnput

    LAB.9

  • 104104

    CB280

    GND

    5V

    P8(SCL)

    P9(SDA)

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    RS232(back)

    CB280

    TX/RX

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    GND

    5V

    SCL

    SDA

    LAB.10

  • CUBLOC

    105105

    LAB.9

  • Cls

    Set Display

    Const Device = CB280

    Dim A As Integer

    Set Display 2,0,0,50

    Cls

    Delay 20

    A = 0

    Do

    Locate 5,0

    Print Dec a

    Delay 200

    Incr a

    Loop

    106106

    LAB.10

  • CUBLOC

    Locate

    Print

    Csron, Csroff

    Print Dec A

    Print Hex B

    1

    107107

    LAB.9

  • 108108

  • 110110

    LAB.1

  • CUBLOC

    111111

    LAB.1

  • 112112

    LAB.1

  • P0

    113113

    CUBLOC

    LAB.1

  • 114114

    LAB.1

  • 115115

    CUBLOC

    LAB.1

  • Usepin

    Set Ladder OnConst Device = CB280Usepin 0,In

    Usepin 2,Out

    Set Ladder On

    LAB.1

    116116

  • 117117

    CUBLOC

    P0

    T0 C0

    1bit

    1bit

    T1 P3

    1bit1bit

    1bit

    16bit

    16bit

    16bit

    F0 T0 D0C0

    T99 D99

    C49

    M0

    P127

    T99

    C49

    F127

    M511

    LAB.1

  • LAB.1

    118118

  • 119119

    CUBLOC

    LAB.1

  • LAB.1

    120120

    5

    6

  • 121121

    CUBLOC

    1

    A

    B

    LAB.1

  • 122122

    Const Device = CB280

    Usepin 0,In

    Usepin 1,In

    Usepin 2,Out

    Set Ladder On

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 2

    I/O 1

    I/O 0

    CB280

    LAB.2

  • 123123

    CUBLOC

    LAB.2

  • 124124

    LAB.2

  • 125125

    CUBLOC

    LAB.2

  • 126126

    LAB.2

  • 127127

    CUBLOC

    1

    A

    B

    C

    LAB.2

  • 128128

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 2

    I/O 1

    I/O 0

    CB280

    Start

    Start

    Stop

    Stop

    Motor

    LAB.3

  • 129129

    CUBLOC

    LAB.3

  • 130130

    Click!

    Click!

    LAB.3

  • Const Device = cb280

    Usepin 0,In

    Usepin 1,In

    Usepin 2,Out

    Usepin 3,In

    Usepin 4,In

    Usepin 5,Out

    Set Ladder On

    131131

    CUBLOC

    I/O 5

    I/O 2

    I/O 4

    I/O 1

    I/O 3

    I/O 0

    CB280

    LAB.3

  • LAB.3

    132132

    Q AQ A&

  • 133133

    CUBLOC

    A

    B

    C

    LAB.3

  • 134134

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 2

    I/O 0

    CB280

    LAB.4

  • 135135

    CUBLOC

    LAB.4

  • 136136

    LAB.4

    Q AQ A&

    INPUT REFLASH

    LADDER SCAN

    OUTPUT REFLASH

  • Do

    Ladderscan

    Loop

    137137

    CUBLOC

    A

    B

    C

    LAB.4

  • 138138

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 2

    I/O 0

    CB280

    Const Device = CB280

    Usepin 0,In

    Usepin 2,Out

    Set Ladder On

    LAB.5

  • 139139

    CUBLOC

    LAB.5

  • 140140

    LAB.5

  • CUBLOC

    A

    141141

    LAB.5

  • Alias

    Const Device = CB280

    Usepin 0, In

    Usepin 2, Out

    Alias P0 = Start

    Alias P2 = Lamp

    Set Ladder On

    Const Device = CB280

    Usepin 0, In, Start

    Usepin 2, Out, Lamp

    Alias M0 = Timesave

    Set Ladder On

    142142

  • Const Device = CB280

    Usepin 0,In

    Usepin 2,Out

    Do

    LadderScan

    Loop

    143143

  • 144144

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 2

    I/O 1

    I/O 0

    CB280

    Start Stop

    Motor

    LAB.6

  • CUBLOC

    145145

    LAB.6

  • 146146

    LAB.6

    A

    Q AQ A&

  • 147147

    D0

    D1

    D2

    D3

    D4

    D5

    D6

    D7

    0

    123

    65535

    3473

    31

    3277

    888

    1000

  • M0 = MAINSW

    M1 = MOTOR

    M2 = IMSI

    148148

  • 149149

    Const Device = CB280

    Usepin 0,In

    Usepin 1,In

    Usepin 2,Out

    Usepin 3,Out

    Usepin 4,Out

    Set Ladder On

  • 150150

  • LAB.1

    152152

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    8 9 10 11 2

    CB280

    I/O I/O I/O I/O I/O

  • CUBLOC

    LADDER

    LADDER

    LADDER

    BASIC

    BASIC

    BASIC

    SINGLE TASK MULTI TASK

    LAB.1

    153153

  • Debug Dec _T(0),cr

    154154

    LAB.1

  • Const Device = CB280

    Ramclear

    Set Ladder On

    Const Device = CB280

    Dim A As Integer

    For A=0 to 50

    _D(A) = 0

    Next

    Set Ladder On

    CUBLOC

    155155

    LAB.1

  • AB

    156156

    LAB.1

  • BASIC LADDER

    BASIC LADDER

    BASIC

    Data Memory

    LADDER

    Data Memory

    I/O Ports

    SRAM

    2KB~24KB

    SRAM

    1KB~4KB

    FLASH

    80KB

    FLASH

    80KB

    157157

  • 158158

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 24 I/O 2

    CB280

    A/D

    (POT)

    LAB.2

  • Const Device = CB280

    Const Device = cb280

    Set Debug Off

    Usepin 2,Out

    Set Ladder On

    Dim B As Byte

    Input 24

    Do

    B = Adin(0)

    _D(0) = B

    Loop

    CUBLOC

    159159

    LAB.2

  • 160160

    LAB.2

    CB280

    I/O 2

    8

    9

    10

    11

    I/O

    I/O

    I/O

    I/O

    I/O

    I/O

    I/O

    I/O

    12

    13

    14

    15

    0 4 8 12

    1 5 9 13

    2 6 10 14

    3 7 11 15

  • CUBLOC

    161161

    LAB.2

  • F2

    F1

    Alias F1 = FOn

    Alias F2 = FInit162162

    LAB.2

  • CUBLOC

    163163

    Set Modbus

    Rx

    Tx

    PC

    CB280

    GND

    1

    2

    3

    4

    5

    6

    7

    8

    9

    SOUT

    SIN

    ATN

    VSS

    P0

    P1

    P2

    P3

    P4

    P5

    P6

    P7

    P8

    P9

    P10

    P11

    TX1

    RX1

    AVDD

    N/C

    P24

    P25

    P26

    P27

    P47

    P46

    P45

    P44

    P43

    P42

    P41

    P40

    VDD

    VSS

    RES

    N/C

    P16

    P17

    P18

    P19

    P20

    P21

    P22

    P23

    P15

    P14

    P13

    P12

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    TTLTX1

    TTLRX1

    AVREF

    P48

    P31

    P30

    P29

    P28

    P32

    P33

    P34

    P35

    P36

    P37

    P38

    P39

    LAB.2

  • Const Device = CB280

    Usepin 0,In

    Usepin 1,In

    Usepin 2,Out

    Set Ladder On

    Do

    Input 24

    _D(10) = Adin(0)

    Loop

    164164

  • 165165

  • 166166

    CB280

    CSG-4S

    GND

    5V

    P3

    P4

    GND

    5V

    SCL

    SDA

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 2

    LAB.3

  • CUBLOC

    167167

    LAB.3

  • 168168

    LAB.3

  • CUBLOC

    169169

    LAB.3

  • 170170

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 2I/O 3

    I/O 0

    CB280

    LAB.4

  • CUBLOC

    171171

    LAB.4

  • 172172

    LAB.4

  • CUBLOC

    173173

    For B=0 to 10

    Debug DEC A,CR

    A = A + 10

    Next

    P5 P6 INTON LAB.4

  • 174174

  • 176176

  • CUBLOC

    177177

  • LAB.1

    178178

  • CUBLOC

    Layer1

    Layer2

    Layer3

    0 1 2 3 4 5 6 7 8 9

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9

    1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3

    LAB.1

    179179

  • 180180

    LAB.1

  • CUBLOC

    181181

    1

    LAB.1

  • 182182

    LAB.2

  • 00

    319

    239

    Layer1

    Layer2

    Layer3

    Glayer 2

    Glayer 3

    CUBLOC

    183183

    LAB.2

  • 184184

    LAB.2

  • CUBLOC

    185185

    LAB.2

  • 186186

    LAB.2

  • CUBLOC

    187187

    LAB.2

  • 188188

    LAB.2

    RND

  • 189189

  • TOUCH PAD

    CONTROLLER

    CUBLOC

    190190

    LAB.3

  • Const Device = Ct1700

    Dim TX1 As Integer, TY1 As Integer

    Contrast 450

    Set Pad 0,4,5

    On Pad Gosub GETTOUCH

    Do

    Loop

    GETTOUCH:

    TX1 = Getpad(2)

    TY1 = Getpad(2)

    Circlefill TX1,TY1,10

    Pulsout 18,300

    Return

    CUBLOC

    191191

    LAB.3

  • Set PAD

    Sample

    Sample

    Sample

    Sample

    MSB Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 LSB

    MSB Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 LSB

    MSB Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 LSB

    MSB Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 LSB

    SCK

    SCK

    SCK

    SCK

    &H00

    &H04

    &H08

    &H0C

    192192

    LAB.3

    On PAD

    GetPAD

  • 0 1 2

    IF Menucheck(0, Tx1, Ty1) = 1 then

    Menureverse 0

    End if

    Menuset 0,2,10,10,50,20

    Menutitle 0,0,0," "

    CUBLOC

    193193

    LAB.3

  • Const Device = CT1720

    Dim TX1 As Integer, TY1 As Integer

    Dim k As Long

    Contrast 450

    Set Pad 0,4,5

    On Pad Gosub abc

    Menuset 0,2,8,16,87,63

    Menutitle 0,13,13," "

    Menuset 1,2,96,16,176,63

    Menutitle 1,13,13," "

    Menuset 2,2,184,16,264,63

    Menutitle 2,13,13," "

    Low 18

    Do

    Loop

    abc:

    TX1 = Getpad(2)

    TY1 = Getpad(2)

    If Menucheck(0,TX1,TY1) = 1 Then

    Menureverse 0

    Pulsout 18,300

    End If

    If Menucheck(1,TX1,TY1) = 1 Then

    Menureverse 1

    Pulsout 18,300

    End If

    If Menucheck(2,TX1,TY1) = 1 Then

    Menureverse 2

    Pulsout 18,300

    End If

    Return

    LAB.3

    194194

  • 195195

  • 196196

    LAB.4

  • CUBLOC

    197197

    1

    23

    LAB.4

  • 198198

    LAB.4 1

    2

  • CUBLOC

    199199

    LAB.4

  • 200200

    LAB.4

    Const Device = Ct1720

    Dim TX1 As Integer, TY1 As Integer

    Dim I As Integer

    Contrast 450

    Set Pad 0,4,5

    On Pad Gosub GETTOUCH

    DEMOFILE

    I =0

    Do

    Loop

    GETTOUCH:

    TX1 = Getpad(2)

    TY1 = Getpad(2)

    If Menucheck(0,TX1,TY1) = 1 Then

    I = I

  • CUBLOC

    201201

    LAB.4

  • 202202

    LAB.5

  • CUBLOC

    203203

    LAB.5

  • Const Device = Ct1720

    Dim TX1 As Integer, TY1 As Integer

    Dim Mode As Integer

    Dim I As Integer

    Contrast 450

    Set Pad 0,4,5

    On Pad Gosub GETTOUCH

    Mainmenu

    Ramclear

    Do

    Loop

    GETTOUCH:

    TX1 = Getpad(2)

    TY1 = Getpad(2)

    Select Case mode

    Case 0

    '

    '

    '

    If Menucheck(0,TX1,TY1) = 1 Then

    BeepAndClear 0

    mode = 1

    Configmenu

    Gosub ProcessPrint

    End If

    If Menucheck(1,TX1,TY1) = 1 Then

    BeepAndClear 1

    mode = 2

    Adminmenu

    End If

    If Menucheck(2,TX1,TY1) = 1 Then

    BeepAndClear 2

    mode = 3

    Sijakmenu

    End If

    Case 1

    '

    '

    '

    If Menucheck(0,TX1,TY1) = 1 Then

    BeepAndClear 0

    mode = 0

    Mainmenu

    End If

    If Menucheck(1,TX1,TY1) = 1 Then

    BeepAndClear 1

    mode = 3

    Sijakmenu

    End If

    Case 2

    '

    '

    '

    If Menucheck(0,TX1,TY1) = 1 Then

    BeepAndClear 0

    mode = 0

    Mainmenu

    End If

    If Menucheck(1,TX1,TY1) = 1 Then

    BeepAndClear 1

    mode = 1

    Configmenu

    Gosub ProcessPrint

    End If

    Case 3

    '

    '

    '

    If Menucheck(0,TX1,TY1) = 1 Then

    BeepAndClear 0

    mode = 0

    Mainmenu

    End If

    If Menucheck(1,TX1,TY1) = 1 Then

    BeepAndClear 1

    mode = 2

    Adminmenu

    End If

    End Select

    Return

    ProcessPrint:

    For I = 0 To 100 Step 10

    Locate 16,8

    Print Dec5 I,"%"

    Delay 200

    Next

    Return

    End

    Sub BeepAndClear(MenuNum As Byte)

    Pulsout 18,300

    Menureverse MenuNum

    Delay 400

    Cls

    Waitdraw

    End Sub

    #include "lightc.inc"

    204204

    LAB.5

  • CUBLOC

    205205

    LAB.5

  • Const Device = Ct1720

    Dim TX1 As Integer, TY1 As Integer '

    Dim UX As Integer, UY As Integer 'UFO

    Dim SCORE As Integer '

    Dim BULLET As Integer '

    Dim Mode As Integer

    Dim TimeV As Integer '

    Dim I As Integer

    Contrast 450

    Set Pad 0,4,5

    On Pad Gosub GETTOUCH

    Ramclear

    Cls

    Delay 100

    Locate 2,14

    Print DEC5 SCORE'

    Menuset 0,2,240,200,300,230

    Menutitle 0,12,7,"Shoot"

    Linestyle 1

    Dotsize 0,0

    Color 1

    Box 120,220,175,239

    Box 140,200,155,220

    Boxfill 105,230,190,239,0

    On timer(10) Gosub MAINPROC

    Do

    Loop

    MAINPROC:

    TimeV = TimeV + 1

    Locate 2,13

    Print DEC5 TimeV / 10

    206206

    LAB.5

  • '' UFO

    '

    UX = UX + 1

    Locate UX,UY

    Print " == "

    If UX > 34 Then

    Locate UX,UY

    Print " "

    UX = 0

    UY = RND(0) MOD 10

    End If

    '

    '

    '

    If BULLET > 0 Then

    Locate 18,BULLET

    Print " "

    Decr BULLET

    If BULLET > 0 Then

    Locate 18,BULLET

    Print "^"

    End If

    '

    ' UFO .

    '

    If BULLET = UY And (UX > 13 And UX < 18) Then

    Locate UX,UY

    Print " **** "

    Pulsout 18,1000

    Locate UX,UY

    Print " "

    UX = 0

    UY = RND(0) MOD 10'

    SCORE = SCORE + 10

    Locate 2,14

    Print DEC5 SCORE'

    BULLET = 0 '

    End If

    End If

    Return

    GETTOUCH:

    TX1 = Getpad(2)

    TY1 = Getpad(2)

    '

    ' .

    '

    If BULLET = 0 Then

    If Menucheck(0,TX1,TY1) = 1 Then

    Pulsout 18,100

    BULLET = 13

    End If

    End If

    Return

    CUBLOC

    207207

    LAB.5

  • 208208

  • 210210

    LAB.1

    Const Device = CB280

    Usepin 0,In

    Usepin 1,In

    Usepin 9,Out

    Set Ladder On

    Usepin 10,Out

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3 I/O 10I/O 9

    I/O 1

    I/O 0

    CB280

    START STOP

    RED GREEN

  • CUBLOC

    211211

    LAB.1

    Start

    Red

    Green

    Stop

  • 212212

    ARM

    DISARM

    VALET

    ~ ~

    ALRAM

    LAB.2

  • 213213

    CUBLOC

    0 1 2 3 4 5 6 7

    0 8 16

    24 32 40 48

    LED Output A/D in Toggle In Push S/W

    0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 70 1 2 3

    I/O 9 I/O 10 I/O 11 I/O 12

    I/O 3

    I/O 1

    I/O 2

    I/O 0

    PIEZO

    CB280

    ARM DISARM

    LAB.2

  • Const Device = CB280

    Usepin 9,Out,LED

    #define F_KEY1 FLAGREG1.BIT0

    #define F_KEY2 FLAGREG1.BIT1

    Const KEYSWIN = 0

    Const DOORSENSOR = 1

    Const SHOCKSENSOR = 2

    Const ACCON = 3

    Const SIREN = 5

    Const DOOROPEN = 10

    Const DOORCLOSE = 11

    Const FLIGHT = 12

    '

    'CuBLOC ..

    '

    ' Port 0 : Remocon High active

    ' port 1 : High active

    ' port 2 : High active

    ' port 3 : High active

    '

    ' port 5 :

  • 215215

    CUBLOCCase 1

    _M(0) = 0

    If F_KEY1 = 1 Then

    MODE = 0

    CHIRP_TIMER = 4

    F_KEY1 = 0

    DOORCLOSE_TIMER = 10

    LIGHT_TIMER = 16

    DELAY_TIMER = 50

    End If

    If F_KEY2 = 1 Then

    MODE = 3

    CHIRP_TIMER = 12

    F_KEY2 = 0

    End If

    Low LED

    Case 2

    If F_KEY1 = 1 Then

    MODE = 1

    CHIRP_TIMER = 8

    F_KEY1 = 0

    DOORCLOSE_TIMER = 10

    End If

    Incr SIREN_TIMER

    Out LED,SIREN_TIMER.BIT3

    Out FLIGHT,SIREN_TIMER.BIT4

    If SIREN_TIMER.BIT3 =1 Then

    Freqout 0,2500

    Else

    Pwmoff 0

    End If

    ' LED FLASH OFF

    'ARM .

    ' 2

    ' OFF

    ' .

    ' .

    '

    '

    'ALRAM

    '

    '

    'VALET

    '

    Case 3

    If F_KEY1 = 1 Then

    MODE = 1

    CHIRP_TIMER = 8

    F_KEY1 = 0

    DOORCLOSE_TIMER = 10

    _M(0) = 0

    End If

    _D(1) = 100

    _M(0) = 1

    End Select

    End Sub

    Sub TIMER_CONTROL()

    Dtzero CHIRP_TIMER

    Dtzero DOOROPEN_TIMER

    Dtzero DOORCLOSE_TIMER

    Dtzero LIGHT_TIMER

    Dtzero DELAY_TIMER

    End Sub

    Sub OUTPUT_PROC()

    If LIGHT_TIMER > 0 Then

    Out FLIGHT,LIGHT_TIMER.BIT3

    End If

    If CHIRP_TIMER > 0 Then

    If CHIRP_TIMER.BIT1 =1 Then

    Freqout 0,2500

    Else

    Pwmoff 0

    End If

    End If

    Out DOOROPEN,DOOROPEN_TIMER

    Out DOORCLOSE,DOORCLOSE_TIMER

    End Sub

    ' LED FLASH

    ' LED FLASH ON

    LAB.2

  • 216216

    On TIMER(5) Gosub MAIN_LOOP

    Do

    Loop

    MAIN_LOOP:

    INPUT_PROC

    MODE_PROC

    OUTPUT_PROC

    TIMER_CONTROL

    Return

    '

    '

    '

    LAB.2

  • 217217

    CUBLOC

    Sub TIMER_CONTROL()

    Dtzero CHIRP_TIMER

    Dtzero DOOROPEN_TIMER

    Dtzero DOORCLOSE_TIMER

    Dtzero LIGHT_TIMER

    Dtzero DELAY_TIMER

    End Sub

    Sub OUTPUT_PROC()

    If LIGHT_TIMER > 0 Then

    Out FLIGHT,LIGHT_TIMER.BIT3

    End If

    If CHIRP_TIMER > 0 Then

    If CHIRP_TIMER.BIT1 =1 Then

    Freqout 0,2500

    Else

    Pwmoff 0

    End If

    End If

    Out DOOROPEN,DOOROPEN_TIMER

    Out DOORCLOSE,DOORCLOSE_TIMER

    End Sub

    LAB.2

  • 218218

    Sub INPUT_PROC()

    If In(KEYSWIN)=1 Then

    Incr KEYTIMER

    Else

    KEYTIMER = 0

    FLAGREG1 = 0

    End If

    If KEYTIMER = 2 Then

    F_KEY1 = 1

    End If

    If KEYTIMER = 30 Then

    F_KEY2 = 1

    End If

    End Sub

    #define F_KEY1 FLAGREG1.BIT0

    #define F_KEY2 FLAGREG1.BIT1

    1

    1

    FLAGREG1

    FLAGREG1 F_KEY2

    F_KEY1

    LAB.2

  • 219219

    CUBLOC

    Sub MODE_PROC()

    Select Case MODE

    Case 0

    _D(1) = 50

    _M(0) = 1

    If F_KEY1 = 1 Then

    MODE = 1

    CHIRP_TIMER = 8

    F_KEY1 = 0

    DOOROPEN_TIMER = 10

    LIGHT_TIMER = 32

    End If

    If DELAY_TIMER = 0 Then

    If In(ACCON) = 1 Or In(DOORSENSOR) = 1 Or In(SHOCKSENSOR) = 1 Then

    MODE = 2

    DOORCLOSE_TIMER = 10

    End If

    End If

    '

    'ARM

    '

    ' LED FLASH

    ' LED FLASH ON

    'DISARM .

    LAB.2

  • 220220

    ..