Je suis en train de préparer un code pour utiliser un AD9850, j'ai reussi à utiliser un encodeur rotatif comme je le souhaite.
Et j'en arrive à la préparation des données hexadecimal pour envoie au générateur de signal.
Dans mikrobasic il y a bien un truc tous fait qui convertie de longint en hexa mais il sort en format texte.
à moins que je face de la detection de caractere pour revenir en veritable hexa je ne vois pas vraiment comment faire.
Auriez vous une petite idée qui pourrait meviter de perdre en temps fou la dessus?
Comme vous le verrez sur le code ci-dessous je me suis arreté à la multiplication par 34360.
Jusque la tous ce passe bien
Code : Tout sélectionner
program test_comutateur_rotatif
' 18h4550 8Mhz
' Declarations section
dim
test_cpt as byte
Mem_A as bit
Mem_B as bit
cpt as longint
conversion as longint
Signal_A as sbit at PortC.0
Signal_B as sbit at PortC.1
Signal_BP as sbit at PortC.6
dim txt as string[10]
dim comptpb as byte
dim comptpb1 as byte
dim comptpb2 as byte
dim manu_on as bit
' Lcd module connections
dim
LCD_RS as sbit at RB4_bit
LCD_EN as sbit at RB5_bit
LCD_D7 as sbit at RB3_bit
LCD_D6 as sbit at RB2_bit
LCD_D5 as sbit at RB1_bit
LCD_D4 as sbit at RB0_bit
dim
LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D7_Direction as sbit at TRISB3_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D4_Direction as sbit at TRISB0_bit
sub procedure ecriture_lcd()
LongIntToStr(cpt, txt)
Lcd_Chr(2,1,txt[0])
Lcd_Chr(2,2,txt[1])
Lcd_Chr(2,3,txt[2])
Lcd_Chr(2,4,txt[3])
Lcd_Chr(2,5,txt[4])
Lcd_Chr(2,6,txt[5])
Lcd_Chr(2,7,txt[6])
Lcd_Chr(2,8,txt[7])
Lcd_Chr(2,9,txt[8])
Lcd_Chr(2,10,txt[9])
end sub
sub procedure ecritureexa_lcd()
LongIntToStr(cpt, txt)
Lcd_Chr(2,1,txt[0])
Lcd_Chr(2,2,txt[1])
Lcd_Chr(2,3,txt[2])
Lcd_Chr(2,4,txt[3])
Lcd_Chr(2,5,txt[4])
Lcd_Chr(2,6,txt[5])
Lcd_Chr(2,7,txt[6])
Lcd_Chr(2,8,txt[7])
Lcd_Chr(2,9,txt[8])
Lcd_Chr(2,10,txt[9])
end sub
main:
ADCON1 = $FF
PORTC = 0 ' set PORTB to 0
TRISC = $FF ' designate PORTB pins as output
LATD = 0 ' set PORTC to 0
TRISD = $00 ' designate PORTC pins as intput
cpt=0
comptpb2 = 0
ecriture_lcd()
' Main program
Mem_B=0
Mem_A=0
Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off
Lcd_Out(1,1,"Test mesure")
While (TRUE)
'Gestion BP
if (Signal_BP=1) and (comptpb<20) then
inc(comptpb)
end if
if (Signal_BP=0)then
comptpb=0
end if
if (comptpb=3) then
comptpb2 = comptpb2 +1
end if
if (comptpb2 = 6 )then
comptpb2 = 0
end if
if (comptpb2 = 0 )then
if (Mem_B=0) then
if (Signal_A = 1 ) then
Mem_A = 1
if (Signal_B= 1 ) then
cpt=cpt+1
ecriture_lcd()
Delay_ms(3)
Mem_A = 0
end if
end if
end if
if (Mem_A=0) then
if (Signal_B = 1 ) then
Mem_B=1
if (Signal_A= 1 ) then
cpt=cpt-1
ecriture_lcd()
Delay_ms(3)
Mem_B=0
end if
end if
end if
end if
if (comptpb2 = 1 )then
if (Mem_B=0) then
if (Signal_A = 1 ) then
Mem_A = 1
if (Signal_B= 1 ) then
cpt=cpt+10
ecriture_lcd()
Delay_ms(3)
Mem_A = 0
end if
end if
end if
if (Mem_A=0) then
if (Signal_B = 1 ) then
Mem_B=1
if (Signal_A= 1 ) then
cpt=cpt-10
ecriture_lcd()
Delay_ms(3)
Mem_B=0
end if
end if
end if
end if
if (comptpb2 = 2 )then
if (Mem_B=0) then
if (Signal_A = 1 ) then
Mem_A = 1
if (Signal_B= 1 ) then
cpt=cpt+100
ecriture_lcd()
Delay_ms(3)
Mem_A = 0
end if
end if
end if
if (Mem_A=0) then
if (Signal_B = 1 ) then
Mem_B=1
if (Signal_A= 1 ) then
cpt=cpt-100
ecriture_lcd()
Delay_ms(3)
Mem_B=0
end if
end if
end if
end if
if (comptpb2 = 3 )then
if (Mem_B=0) then
if (Signal_A = 1 ) then
Mem_A = 1
if (Signal_B= 1 ) then
cpt=cpt+1000
ecriture_lcd()
Delay_ms(3)
Mem_A = 0
end if
end if
end if
if (Mem_A=0) then
if (Signal_B = 1 ) then
Mem_B=1
if (Signal_A= 1 ) then
cpt=cpt-1000
ecriture_lcd()
Delay_ms(3)
Mem_B=0
end if
end if
end if
end if
if (comptpb2 = 4 )then
if (Mem_B=0) then
if (Signal_A = 1 ) then
Mem_A = 1
if (Signal_B= 1 ) then
cpt=cpt+10000
ecriture_lcd()
Delay_ms(3)
Mem_A = 0
end if
end if
end if
if (Mem_A=0) then
if (Signal_B = 1 ) then
Mem_B=1
if (Signal_A= 1 ) then
cpt=cpt-10000
ecriture_lcd()
Delay_ms(3)
Mem_B=0
end if
end if
end if
end if
if (comptpb2 = 5 )then
if (Mem_B=0) then
if (Signal_A = 1 ) then
Mem_A = 1
if (Signal_B= 1 ) then
cpt=cpt+100000
ecriture_lcd()
Delay_ms(3)
Mem_A = 0
end if
end if
end if
if (Mem_A=0) then
if (Signal_B = 1 ) then
Mem_B=1
if (Signal_A= 1 ) then
cpt=cpt-100000
ecriture_lcd()
Delay_ms(3)
Mem_B=0
end if
end if
end if
end if
conversion = cpt * 34360
LongIntToHex(conversion, txt)
ecritureexa_lcd()
Wend
end. 
