-
        

Ergebnis 1 bis 2 von 2

Thema: SRF10 Ausgabe auf Terminal

  1. #1

    SRF10 Ausgabe auf Terminal

    Anzeige

    Hallo Robotics,

    Wir wollen einen SRF10 an der der MU2.0 betreiben. Das Standartprogramm und der SRF10 laufen. Leider haben wir kein LCD, was wir für unser Projekt auch nicht benötigen. Wie kann ich mir die Daten des SRF10 auf einem Terminal anzeigen lassen.

    Vielen Dank für Eure Hilfe
    '----------------------------------------------------------------------------------------------------'
    '************************************************* ********************'
    '* WINDT SYSTEMS *'
    '* SRF10 RANGE VIA EMULATED I2C BUS b1.0 for CCIUM2.0 with CCIAB2.0 *'
    '* 2006 *'
    '************************************************* ********************'
    '----------------------------------------------------------------------------------------------------'
    'This (beta) software, with the C-Control I Unit M2.0 mounted on the C-Control I Application Board 2.0,'
    'will fire and read the SRF10 range and display the data on the LCD as Range in cm.'
    'Communication with the SRF10 is via an emulated I2C bus, this is due to the fact that the'
    'standard I2C "IIC" software for the CCIUM2.0 does NOT check for clock stretching!'
    'The emulated SDA line is via port 4.'
    'The emulated SCL line is via port 5.'
    'Feel free to use and share this software!'
    '----------------------------------------------------------------------------------------------------'
    '**************** I/O PORTS ****************'
    define sda port[9]
    define scl port[10]
    define lcd_light_off port[16]
    '*******************************************'
    '**************** VARIABLES ****************'
    define control_flags byte[1]
    define i2c_nack bit[1]
    define i2c_last bit[2]
    define i2c_nack_count byte[2]
    define i2c_byte byte[3]
    define i2c_out_bit bit[24]
    define i2c_in_bit bit[17]
    define i2c_loop byte[4]

    define range word[3]
    '*******************************************'
    '**************** CONSTANTS ****************'
    DEFINE srf10_gain 16 'SRF10 GAIN / (0 to 16) DEFAULT = 16'
    define srf10_range 180 'SRF10 RANGE / (0 to 255) DEFAULT = 255'
    '*******************************************'
    '****************** SETUP ******************'
    PRINT"#ON_LCD#"; : print"#INIT#"; : print"#CLR#"; : print"#OFF#"; : lcd_light_off = off
    print"#ON_CONFIG#"; : put &b1000 : print"#OFF#";
    #try_again
    gosub initialize_srf10
    if i2c_nack then goto try_again
    '*******************************************'
    '***************** PROGRAM *****************'
    #start
    gosub get_srf10_range
    if i2c_nack then goto start
    print"#ON_LCD#";
    print"#L101#";
    print"Range = ";range;"cm";" ";
    print"#OFF#";
    goto start
    '*******************************************'
    '*************** SUBROUTINES ***************'
    #get_srf10_range
    #fire_srf10
    gosub start_i2c
    i2c_byte = &he0 : gosub write_byte_i2c
    i2c_byte = 0 : gosub write_byte_i2c
    i2c_byte = &h51 : gosub write_byte_i2c
    gosub stop_i2c
    if i2c_nack_count > 50 then goto no_ack_from_srf10
    if i2c_nack then goto fire_srf10
    #read_range
    #srf10_wait_and_setup
    gosub start_i2c
    i2c_byte = &he0 : gosub write_byte_i2c
    i2c_byte = 2 : gosub write_byte_i2c
    gosub stop_i2c
    #pass_srf10_setup
    if i2c_nack_count > 100 then goto no_ack_from_srf10
    if i2c_nack then goto srf10_wait_and_setup
    #read_srf10_data
    gosub start_i2c
    i2c_byte = &he1 : gosub write_byte_i2c
    gosub read_byte_i2c : range = i2c_byte * 256
    gosub read_last_byte_i2c : range = range + i2c_byte
    gosub stop_i2c
    if i2c_nack then goto pass_srf10_setup
    return

    #start_i2c
    sda = 0 : scl = 0
    return

    #stop_i2c
    sda = 0 : deact scl : deact sda
    return

    #write_byte_i2c
    for i2c_loop = 1 to 8
    sda = i2c_out_bit
    deact scl
    #write_byte_i2c_clock_stretch
    if not scl then goto write_byte_i2c_clock_stretch
    scl = 0
    i2c_byte = i2c_byte shl 1
    next
    deact sda
    deact scl
    #write_byte_i2c_ack_clock_stretch
    if not scl then goto write_byte_i2c_ack_clock_stretch
    i2c_nack = sda
    scl = 0
    if i2c_nack then goto i2c_error
    i2c_nack_count = 0
    return
    #i2c_error
    i2c_nack_count = i2c_nack_count + 1
    goto stop_i2c

    #read_byte_i2c
    i2c_last = 0
    #get_i2c_byte
    deact sda
    for i2c_loop = 1 to 8
    deact scl
    #read_byte_i2c_clock_stretch
    if not scl then goto read_byte_i2c_clock_stretch
    i2c_in_bit = sda
    scl = 0
    if i2c_loop < 8 then i2c_byte = i2c_byte shl 1
    next
    if i2c_last then deact sda else sda = 0
    deact scl
    #read_byte_i2c_ack_clock_stretch
    if not scl then goto read_byte_i2c_ack_clock_stretch
    scl = 0
    return

    #read_last_byte_i2c
    i2c_last = 1
    goto get_i2c_byte
    '*******************************************'
    '******* INITIALIZATION SUBROUTINES ********'
    #initialize_srf10
    gosub start_i2c
    i2c_byte = &he0 : gosub write_byte_i2c
    i2c_byte = 1 : gosub write_byte_i2c
    i2c_byte = srf10_gain : gosub write_byte_i2c
    i2c_byte = srf10_range : gosub write_byte_i2c
    gosub stop_i2c
    if i2c_nack_count > 12 then goto no_ack_from_srf10
    if i2c_nack then goto initialize_srf10
    return
    '*******************************************'
    '****************** DATA *******************'

    '*******************************************'
    '************* ERROR MESSAGES **************'
    #no_ack_from_srf10
    beep 1,1,1:beep 10,1,1:beep 1,1,1:beep 10,1,1
    print"#ON_LCD#";
    print"#CLR#";
    print"E-I2C ERROR:";
    print"#L201#";
    print"SRF08 not found";
    pause 300
    print"#CLR#";
    print"#OFF#";
    return
    '*******************************************'

  2. #2
    Benutzer Stammmitglied
    Registriert seit
    28.08.2006
    Beiträge
    48
    Hello,
    Here are the changes to display the range on a terminal program:
    Greetings,
    H.J. Windt


    '***************** PROGRAM *****************'
    #start
    gosub get_srf10_range
    if i2c_nack then goto start
    print"Range = ";range;"cm"
    pause 25 '<- lower this number or delete this line for speed'
    goto start
    '*******************************************'

    '************* ERROR MESSAGES **************'
    #no_ack_from_srf10
    print"E-I2C ERROR:"
    print"SRF08 not found"
    pause 25
    return
    '*******************************************'

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •