Code en basic vers c

Résolu
gogi000 - 14 août 2012 à 14:12
cs_ghuysmans99
Messages postés
3983
Date d'inscription
jeudi 14 juillet 2005
Statut
Membre
Dernière intervention
30 juin 2013
- 16 août 2012 à 10:28
bonjour,

y aurait-il moyen de pouvoir transformer un code écrit en basic vers le c?

je dois écrire une programmation d'un pic en c
mais j'ai trouver un code déja écris en basic, le soucis est de le retranscrire en c.

comme par exemple:
as byte par rapport en c ?
as word?
dim = define ou int?
et surtout le

For i = 0 to PosDecPoint+2
DisplayString[i] = SensorString[i]
Next i
par rapport au c ?

dont voici la programmation:

program IR_Thermometer
dim LCD_RS as sbit at RB2_bit
LCD_EN as sbit at RB3_bit
LCD_D4 as sbit at RB4_bit
LCD_D5 as sbit at RB5_bit
LCD_D6 as sbit at RB6_bit
LCD_D7 as sbit at RB7_bit

LCD_RS_Direction as sbit at TRISB2_bit
LCD_EN_Direction as sbit at TRISB3_bit
LCD_D4_Direction as sbit at TRISB4_bit
LCD_D5_Direction as sbit at TRISB5_bit
LCD_D6_Direction as sbit at TRISB6_bit
LCD_D7_Direction as sbit at TRISB7_bit

' End LCD module connections

' Variable definitions

dim SensorLow as byte ' Raw temp. low byte
SensorHigh as byte ' Raw temp. high byte
SensorRaw as word ' Raw temp. word
SensorRawCur as word ' Current raw temp.
SensorRawMax as word ' Max. raw temp.
SensorRawMin as word ' Min. raw temp.
Sensor as float ' Real temp (floating point)
SensorString as string[9]
DisplayString as string[9]
PEC as byte ' Control byte (read but not used)
com as byte ' MLX90614 command
PosDecPoint as byte ' Decimal point position
i as byte

' Procedure definition

' Read Temperature From MLX90614
' Input : com specify temp. to read
' Output : raw temp as a word

Sub procedure Read_temp(dim com as byte)

I2C1_Start() ' issue I2C start signal
I2C1_Wr(0x00) ' send address (device address + W)
I2C1_Wr(com) ' send command
I2C1_Repeated_Start() ' issue I2C signal repeated start
I2C1_Wr(0x01) ' send address (device address + R)
SensorLow = I2C1_Rd(1) ' Read temp. low byte (acknowledge)
SensorHigh = I2C1_Rd(1)' Read temp. high byte (acknowledge)
PEC = I2C1_Rd(1) ' Read PEC (not used) (acknowledge)
I2C1_Stop() ' issue I2C stop signal
SensorRaw = SensorLow + (SensorHigh << 8) ' Build temp. word

End sub

' Convert raw data in SensorRaw
' to displayable string in DisplayString

Sub procedure Convert_raw

Sensor = SensorRaw * 0.02 - 273.15 ' Raw temp to Celsius
FloatToStr (Sensor, SensorString) ' Float to string
PosDecPoint = Strchr (SensorString,".") ' Search for dec. point
For i = 0 to PosDecPoint+2 ' Limit display to two digits
DisplayString[i] = SensorString[i] ' after decimal point
Next i
DisplayString[PosDecPoint+3]= ""
DisplayString = DisplayString + " C"

End sub

' Main Program

main:

' Initialize I/O

PORTB = 0
TRISB = 0 ' All PORTB lines as output
ADCON1 = 0x0F ' Configure AN pins as digital I/O

' Initialize LCD display

Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off

' Initialize Min and Max object temp.

SensorRawMax = 0
SensorRawMin = 0xFFFF

' Initialize SMBus

I2C1_Init(100000) ' I2C/SMBus Clock speed 100 kHz
SETBIT (SSPSTAT,6) ' Force MSSP in SMBus mode

while true

Read_temp (0x06) ' Read ambiant temp.

Convert_raw

Lcd_Out(1,1,"T Amb. : ") ' Write ambiant temp in first row
Lcd_Out(1,10,DisplayString)

Read_temp (0x07) ' Read object temp.

SensorRawCur = SensorRaw ' Make obj. temp. current temp.

If SensorRawCur > SensorRawMax Then ' Is current temp. higher than max. temp.
SensorRawMax = SensorRawCur ' Make max. temp. equal current temp.
End if

If SensorRawCur < SensorRawMin Then ' Is current temp. lower than min. temp.
SensorRawMin = SensorRawCur ' Make min. temp. equal current temp.
End if

Convert_raw

Lcd_Out(2,1,"T Obj. : ") ' Write object temp in second row
Lcd_Out(2,10,DisplayString)

SensorRaw = SensorRawMax
Convert_raw

Lcd_Out(3,1,"T Max. : ") ' Write Max object temp in third row
Lcd_Out(3,10,DisplayString)

SensorRaw = SensorRawMin
Convert_raw

Lcd_Out(4,1,"T Min. : ") ' Write Min object temp in fourth row
Lcd_Out(4,10,DisplayString)

Delay_ms (1000)

wend

end.

en attendant une réponse
merci.

3 réponses

cs_ghuysmans99
Messages postés
3983
Date d'inscription
jeudi 14 juillet 2005
Statut
Membre
Dernière intervention
30 juin 2013
16
14 août 2012 à 15:47
#define unsigned char byte
#define unsigned short word
/*Dim x as byte */ byte x;
/*Dim y as word */ word y;
/*For i = 0 To y*/ for (i=0; i<=y; i++) {
DisplayString[i] = SensorString[i]; //juste un ; en plus
/*Next i*/ }



VB.NET is good ... VB6 is better
Utilise Réponse acceptée quand un post répond à ta question
3
merci de ta réponse

et pour le reste du code est-ce que ce n'est qu'une retransription litéraire en c?

facilement traduisible?

si tu vois ce que je dis?

merci
0
cs_ghuysmans99
Messages postés
3983
Date d'inscription
jeudi 14 juillet 2005
Statut
Membre
Dernière intervention
30 juin 2013
16
16 août 2012 à 10:28
ce n'est qu'une retransription littéraire en c?
Littérale, plutôt ?
Non, des trucs comme ça DisplayString = DisplayString + " C" --> strcat(DisplayString, " C");
Une ligne que je ne sais pas traduire en C : dim LCD_RS as sbit at RB2_bit

VB.NET is good ... VB6 is better
Utilise Réponse acceptée quand un post répond à ta question
0