¿que opinan, será posible convertirlo?, porque estudio electrónica y casi no conozco el lenguaje C y la verdad jamás he trabajado en BASIC
Código:
program compass dim sw_revision,ee_high, ee_low,ee_byte as byte data as word Text as char[17] sub procedure initLCD PORTB = 0 ' Clear portb TRISB = 0 ' Designate portb as output (LCD is connected to portb) INTCON = 0 ' Disable all interrupts LCD_init(PORTB) ' Initialize (4-bit interface connection) LCD_cmd(LCD_CURSOR_OFF) ' Send command to LCD (cursor off) LCD_cmd(LCD_CLEAR) ' Send command to LCD (clear LCD) text = "CMPS03 Compass" LCD_Out(1,1,text) ' Print string a on LCD, 1st row, 1st column end sub main: initlcd delay_ms(1000) ' wait before every system component is ready while true 'infinite loop I2C_Init(100000) ' initialize I2C module 100 kHz clk, full master mode '===============start reading======================== I2C_Start ' issue I2C start signal I2C_Wr(0xC0) ' send byte via I2C to cmps03 addres 0xC0 I2C_Wr(0x00) ' send byte (register adres) I2C_Repeated_Start ' issue I2C signal repeated start I2C_Wr(0xC1) ' send byte (request data from EEPROM) sw_revision=0 ' reset sw_revision to check if it is really read from cmps03 sw_revision = I2C_rd(1) ' Read the software version from register 0 and send acknowledge ee_byte=0 ' reset sw_revision to check if it is really read from cmps03 delay_ms(5) ee_byte = I2C_rd(1) ' Read the unused register from register 1 and send acknowledge (it should read 0x80) delay_ms(5) ee_high=0 ee_high = I2C_rd(1) ' Read the highbyte data and send acknowledge delay_ms(5) ee_low=0 ee_low = I2C_rd(0) ' Read the low byte data and do NOT send acknowledge I2C_stop ' issue I2C stop sinal '===============format and display data======================== data = word(ee_high << 8) + ee_low 'Combine highbyte and low byte LCD_cmd(LCD_CLEAR) ' Send command to LCD (clear LCD) bytetostr(sw_revision,text)' Format low_byte LCD_Out(1,1,text) ' and print it on LCD bytetostr(ee_byte,text) ' Format low_byte LCD_Out(1,5,text) ' and print it on LCD bytetostr(ee_low,text) ' Format low_byte LCD_Out(2,1,text) ' and print it on LCD bytetostr(ee_high,text) ' Format high_byte LCD_Out(2,5,text) ' and print it on LCD wordToStr(data,text) ' Format low_byte LCD_Out(2,10,text) ' and print it on LCD delay_ms(500) 'wait 0.5 second before next measurement wend end.
Por ejemplo, sé que en lenguaje C no existe el tipo word declarado ahí en BASIC, no sé que otras cosas deba cambiar, saludos.