GeSHi (freebasic):Dim t2_ms As WordDim t2_ms_contar As WordDim t1_ms As WordDim t1_ms_contar As WordDim n_rand As ByteDim i As ByteDim d_var As ByteDim d_set(7) As ByteDim un As ByteDim de As ByteDim d_varu As ByteDim d_vard As ByteAllDigitalt1_ms = 0t1_ms_contar = 2000 'milisegundos a contart2_ms = 0t2_ms_contar = 500 'base para intermitenciaTMR0 = 0TRISA = %000010TRISB = 0TRISC = 0PORTB = 0PORTC = 0 d_var = 20 'predeterminado 20d_set(0) = 4d_set(1) = 6d_set(2) = 8d_set(3) = 10d_set(4) = 12d_set(5) = 20d_set(6) = 99 OPTION_REG.T0CS = 0OPTION_REG.PSA = 0OPTION_REG.PS0 = 1OPTION_REG.PS1 = 0OPTION_REG.PS2 = 0INTCON.TMR0IF = 0INTCON.TMR0IE = 1INTCON.PEIE = 1EnableGoto mainopcion: i = 0 While t1_ms < 3000 d_var = d_set(i) If d_var < 10 Then d_varu = d_var d_vard = 10 Else d_varu = d_var - (d_var / 10) * 10 d_vard = d_var / 10 Endif Select Case t2_ms Case <= 300 'uso la base de t2 para generar la intermitencia en Opciones Call display(d_varu, d_vard) Case < 600 '600 Call display(11, 11) Case Else t2_ms = 0 EndSelect If PORTA.1 = 1 Then While PORTA.1 = 1 Select Case t2_ms Case <= 300 '300 Call display(d_varu, d_vard) Case < 600 '600 Call display(11, 11) Case Else t2_ms = 0 EndSelect Wend i = i + 1 If i = 7 Then i = 0 t1_ms = 0 Endif Wendmain: Call display(10, 10) 'del 0 al 9 son numeros, el 10 es "-" y el 11 es vacio If PORTA.1 = 1 Then t1_ms = 0 TMR0 = 0 t1_ms_contar = 2000 While RA1 = 1 Call display(10, 10) If t1_ms = 2000 Then TMR0 = 0 t1_ms = 0 t1_ms_contar = 5000 t2_ms = 0 t2_ms_contar = 600 While RA1 = 1 Wend Goto opcion Endif Wend n_rand = TMR0 Mod d_var If n_rand = 0 And d_var = 99 Then n_rand = 0 If n_rand = 0 And d_var <> 99 Then n_rand = 1 Select Case n_rand 'select case para separar Unidad y Decena Case < 10 un = n_rand de = 0 Case Else un = n_rand - (n_rand / 10) * 10 de = n_rand / 10 EndSelect t1_ms = 0 t1_ms_contar = 1000 TMR0 = 0 While t1_ms < 1000 Call display(un, de) Wend EndifGoto mainEnd Proc display(unidad As Byte, decena As Byte)PORTB = LookUp(0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x18, 0xbf, 0xff), unidadPORTC = %01WaitMs 5PORTC = %11WaitMs 2PORTB = LookUp(0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x18, 0xbf, 0xff), decenaPORTC = %10WaitMs 5PORTC = %11WaitMs 2End Proc On Interrupt Save System If t1_ms < t1_ms_contar Then t1_ms = t1_ms + 1 If t2_ms < t2_ms_contar Then t2_ms = t2_ms + 1 TMR0 = 0 INTCON.TMR0IF = 0Resume
GeSHi (freebasic):AllDigitalDim piso As ByteDim pos As ByteDim i As ByteDim ii As ByteDim salir As ByteDim t1_ms As WordDim t1_ms_contar As Wordt1_ms = 0OPTION_REG.T0CS = 0OPTION_REG.PSA = 0OPTION_REG.PS0 = 0OPTION_REG.PS1 = 1OPTION_REG.PS2 = 0INTCON.T0IF = 0INTCON.T0IE = 1EnableTRISA = 0TRISB = 0PORTB = 0PORTA = 0main: Gosub plataformas Gosub giro_vertical Gosub barras_verticales Gosub espiral Gosub aleatorioGoto mainEnd plataformas:piso = 1t1_ms = 0t1_ms_contar = 1000salir = 0 While salir < 5 t1_ms = 0 While t1_ms < 200 For i = 1 To 3 For ii = 1 To 3 Call mostrar(ii, i) WaitMs 1 Next ii Next i Wend t1_ms = 0 While t1_ms < 200 For i = 1 To 3 For ii = 4 To 6 Call mostrar(ii, i) WaitMs 1 Next ii Next i Wend t1_ms = 0 While t1_ms < 200 For i = 1 To 3 For ii = 7 To 9 Call mostrar(ii, i) WaitMs 1 Next ii Next i Wend t1_ms = 0 While t1_ms < 200 For i = 1 To 3 For ii = 3 To 9 Step 3 Call mostrar(ii, i) WaitMs 1 Next ii Next i Wend t1_ms = 0 While t1_ms < 200 For i = 1 To 3 For ii = 2 To 8 Step 3 Call mostrar(ii, i) WaitMs 1 Next ii Next i Wend t1_ms = 0 While t1_ms < 200 For i = 1 To 3 For ii = 1 To 7 Step 3 Call mostrar(ii, i) WaitMs 1 Next ii Next i Wend salir = salir + 1 WendReturn giro_vertical: piso = 2 salir = 0 t1_ms = 0 t1_ms_contar = 1000 While salir < 10 While t1_ms < 150 For i = 1 To 9 Call mostrar(i, piso) WaitMs 1 Next i Wend t1_ms = 0 While t1_ms < 150 For i = 1 To 3 Call mostrar(i, 3) WaitMs 1 Next i For i = 4 To 6 Call mostrar(i, 2) WaitMs 1 Next i For i = 7 To 9 Call mostrar(i, 1) WaitMs 1 Next i Wend t1_ms = 0 While t1_ms < 150 For i = 1 To 3 For ii = 4 To 6 Call mostrar(ii, i) WaitMs 1 Next ii Next i Wend t1_ms = 0 While t1_ms < 150 For i = 7 To 9 Call mostrar(i, 3) WaitMs 1 Next i For i = 4 To 6 Call mostrar(i, 2) WaitMs 1 Next i For i = 1 To 3 Call mostrar(i, 1) WaitMs 1 Next i Wend t1_ms = 0 While t1_ms < 150 For i = 1 To 9 Call mostrar(i, piso) WaitMs 1 Next i Wend salir = salir + 1 WendReturn barras_verticales:pos = 1piso = 1While piso < 4 Call mostrar(pos, piso) WaitMs 100 pos = pos + 1 If pos = 10 Then piso = piso + 1 pos = 1 EndifWendReturn aleatorio: i = 0 While i < 100 pos = (TMR0 Mod 9) + 1 WaitUs 25 piso = (TMR0 Mod 3) + 1 WaitUs 25 Call mostrar(pos, piso) WaitMs 50 i = i + 1 WendReturn espiral: pos = 0 piso = 1 While piso < 4 For i = 1 To 3 pos = i Call mostrar(pos, piso) WaitMs 150 Next i pos = 6 Call mostrar(pos, piso) WaitMs 150 For i = 9 To 7 Step -1 pos = i Call mostrar(pos, piso) WaitMs 150 Next i pos = 4 Call mostrar(pos, piso) WaitMs 150 piso = piso + 1 Wend t1_ms = 0 While t1_ms < 1000 For i = 1 To 9 Call mostrar(i, 3) WaitMs 1 Next i Call mostrar(5, 2) WaitMs 1 Call mostrar(5, 1) WaitMs 1 Wend Return Proc mostrar(posicion As Byte, nivel As Byte) PORTB = LookUp(%0000, %0001, %0010, %0011, %0100, %0101, %0110, %0111, %1000, %1001), posicion PORTA = LookUp(%111, %110, %101, %011), nivelEnd Proc On Interrupt Save System If t1_ms < t1_ms_contar Then t1_ms = t1_ms + 1 TMR0 = 130 INTCON.T0IF = 0Resume
GeSHi (freebasic):AllDigitalTRISA = %00000001TRISB = 0Dim i As ByteDim accion As Bytei = 1accion = 1main: If RA0 = 1 Then While RA0 = 1 Wend i = i + 1 If i = 4 Then i = 1 PORTB = 0 Endif Call led(i, accion) WaitMs 300Goto mainEnd Proc led(i1 As Byte, acc As Byte)If acc = 1 Then Select Case i1 Case 1 PORTB.0 = 1 Case 2 PORTB.1 = 1 Case 3 PORTB.2 = 1 EndSelectElse Select Case i1 Case 1 PORTB.0 = 0 Case 2 PORTB.1 = 0 Case 3 PORTB.2 = 0 EndSelectEndifIf accion = 0 Then accion = 1Else accion = 0Endif End Proc