Hola amigos necesito ayuda con la libreria button; estoy diseñando el soft para mi insoladora y estoy trabajando con el TMR0 que supuestamente es mas dificil de usar que la libreria button de mikrobasic pero siguiendo el datasheet me a quedado bastante claro (aunque no se calcular todavia muy bien los tiempos, para ello utilizo un soft que he encontrado en el foro).
Bueno al caso lo que quiero es que cuando pulse el boton y el timer este parado empieze a andar pero no lo consigo.
este es mi codigo:
program insoladora
dim LCD_RS as sbit at RB4_bit
LCD_EN as sbit at RB5_bit
LCD_D4 as sbit at RB0_bit
LCD_D5 as sbit at RB1_bit
LCD_D6 as sbit at RB2_bit
LCD_D7 as sbit at RB3_bit
LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit
' End Lcd module connections
dim txt1 as string[16]
txt2 as string[3]
txt3 as string[8]
txt4 as char[7]
i as byte
oldstate as byte
counter as integer
segundos as integer
ts1 as TimeStruct
tinicial as TimeStruct
sub procedure final()
sound_play(659.26,125)
sound_play(659.26,125)
delay_ms(125)
sound_play(659.26,125)
delay_ms(125)
sound_play(659.26,125)
sound_play(783.99,250)
end sub
sub procedure formatear(dim byref tiempo as TimeStruct)
dim temp as string[3]
bytetostr(tiempo.mn,temp)
ltrim(temp)
if tiempo.mn < 10 then
txt1 = "0" + temp
else
txt1 = temp
end if
txt1 = txt1 + ":"
bytetostr(tiempo.ss,temp)
ltrim(temp)
if tiempo.ss < 10 then
txt1 = txt1 + "0" + temp
else
txt1 = txt1 + temp
end if
end sub
sub procedure interrupt
counter = counter + 1
TMR0L = 8
INTCON.2 = 0
if counter = 1000 then
if ts1.ss = 0 then
if ts1.mn = 0 then
T0CON.7 = 0
final()
else
if ts1.ss = 0 then
ts1.mn = ts1.mn - 1
ts1.ss = 59
else
ts1.ss = ts1.ss - 1
end if
end if
else
ts1.ss = ts1.ss - 1
end if
counter = 0
end if
end sub
main:
RCON.7 = 0
INTCON.7 = 1
INTCON.5 = 1
INTCON.2 = 0
T0CON = %01000010
TRISB = 0
PORTB = 0xFF
TRISB = 0x00
TRisa.4 = 1
Portb.6 = 0
Sound_init(PORTA,5)
adcon0=0 ' Sin ADC's, Sin Comparadores PORTA Entrada
adcon1=15
cmcon=7
Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off
tinicial.mn = EEPROM_read(0)
Delay_ms(20)
tinicial.ss = EEPROM_read(1)
oldstate = 0
T0CON = %01000010
while TRUE
if (Button(PORTA, 4, 50, 0) and T0CON.7 = 0) then
oldstate = 255
end if
if (oldstate and Button(PORTA, 4, 50, 1) and T0CON.7 = 0) then
ts1 = tinicial
T0CON.7 = 1
oldstate = 0
end if
If i > ts1.ss then
'sound_play(698,250)
i = ts1.ss
end if
formatear(ts1)
lcd_out(1,1,txt1)
bytetostr(oldstate,txt2)
bytetostr(T0CON, txt3)
lcd_out(2,1, txt2)
lcd_out(2,5,txt3)
wend
end.
y este mi esquema:
os he resaltado el circuito del boton
Gracias.