$crystal = 1000000 'CRISTAL INTERNO DE 1 MHZ
Config Portb = Output 'CONFIGURAR PORTB COMO SALIDAS EN 0 LOGICO
Do 'LAZO INFINITO
Portb = 255 'ENCENIENDO LOS LEDS EN EL PORTB
Waitms 150 'ESPERA DE 150 MS
Portb = 0 'APAGO LOS LEDS EN EL PORTB
Waitms 150 ' ESPERA 150 MS
Loop
End ' FIN DEL PROGRAMA
$crystal = 1000000 'CRISTAL INTERNO DE 1 MHZ
'*******************************************************************
'*** ENE STE EJEMPLO VAMOS A REALIZAR EL PARPADEO DE LOS LEDS... PERO VAMOS
'*** VAMOS A VER COMO SE PUEDE CONFIGURAR BIT A BIT EL I/O DE UN PUERTO....
'*** PARA ESTO VAMOS A USAR EL COMANDO DDR.... EL CUAL DEBE IR ACOMPAÑADO DEL
'*** COMANDO PORT......
'*** ACA UNA BREVE DESCRIPCION DE ESTOS COMANDOS..
'*** DDBn PORTBn I/O Pull up Comment
'*** 0 0 Input No Tri-state (Hi-Z)
'*** 0 1 Input Yes PBn will source current if ext. pulled low.
'*** 1 0 Output No Push-Pull Zero Output
'*** 1 1 Output No Push-Pull One Output
'*** DECIR BREVEMENTO QUE DEPENDIENDO DE LOS VALORES QUE DEMOS A ESTOS PARAMETROS
'*** OBTENDREMOS SALIDAS O ENTRADAS EN UN PUERTO...
'*** PARA ESTE EJEMPLO VAMOS A CONFIGURAR BIT A BIT EL PORTB PARA QUE SEAN SALIDAS EN 0 LOGICO
'*** POR LO QUE LOS VALORES DEBEN SER DDRn 1 Y PORTn 0..
Ddrb.0 = 1
Portb.0 = 0
Ddrb.1 = 1
Portb.1 = 0
Ddrb.2 = 1
Portb.2 = 0
Ddrb.3 = 1
Portb.3 = 0
Ddrb.4 = 1
Portb.4 = 0
Ddrb.5 = 1
Portb.5 = 0
Ddrb.6 = 1
Portb.6 = 0
Ddrb.7 = 1
Portb.7 = 0
Dim Count As Byte
Count = 0
Do 'LAZO INFINITO
Portb = 255 'ENCENIENDO LOS LEDS EN EL PORTB
Waitms 300 'ESPERA DE 150 MS
Portb = 0 'APAGO LOS LEDS EN EL PORTB
Waitms 300
Incr Count ' ESPERA 150 MS
Loop Until Count = 255
End
$crystal = 1000000 'CRISTAL INTERNO DE 1 MHZ
'*** DDBn PORTBn I/O Pull up Comment
'*** 0 0 Input No Tri-state (Hi-Z)
'*** 0 1 Input Yes PBn will source current if ext. pulled low.
'*** 1 0 Output No Push-Pull Zero Output
'*** 1 1 Output No Push-Pull One Output
'*** DECIR BREVEMENTO QUE DEPENDIENDO DE LOS VALORES QUE DEMOS A ESTOS PARAMETROS
'*** OBTENDREMOS SALIDAS O ENTRADAS EN UN PUERTO...
'*** PARA ESTE EJEMPLO VAMOS A CONFIGURAR BIT A BIT EL PORTB PARA QUE SEAN SALIDAS EN 0 LOGICO
'*** POR LO QUE LOS VALORES DEBEN SER DDRn 1 Y PORTn 0..
Config Portb = Output
Dim I As Byte
Portb = 1
Waitms 300
Do 'LAZO INFINITO
For I = 1 To 7 'ESTRUCTURA FOR
Rotate Portb , Left 'SENTENCIA ROTATE QUE MUEVE BIT A BIT
Waitms 300 'IZQUIERDA COMO PORTB INICIA EN 1 DESPUES DE O VECES
Next ' SU VALOR SERA 128
For I = 1 To 7 'VICEVERSA A KA ESTRUCTURA ANTERIOR
Rotate Portb , Right
Waitms 300
Next
Loop 'LAZO INFINITO
End
$crystal = 1000000 'CRISTAL INTERNO DE 1 MHZ
Config Portb = Output
Dim I As Byte
Declare Sub Izq() 'declaracion subrutinas
Declare Sub Dere()
Do 'LAZO INFINITO
Call Izq() 'ir a subrutina izquierda
Call Dere() 'ir a subrutina derecha
Loop 'LAZO INFINITO
Sub Izq()
Portb = 1
Waitms 150
Portb = 2
Waitms 150
Portb = 4
Waitms 150
Portb = 8
Waitms 150
Portb = 16
Waitms 150
Portb = 32
Waitms 150
Portb = 64
Waitms 150
Portb = 128
Waitms 150
End Sub
Sub Dere()
Portb = 64
Waitms 150
Portb = 32
Waitms 150
Portb = 16
Waitms 150
Portb = 8
Waitms 150
Portb = 4
Waitms 150
Portb = 2
Waitms 150
End Sub
End ' FIN DEL PROGRAMA
$crystal = 1000000 'CRISTAL INTERNO DE 1 MHZ
Config Portb = Output
Declare Sub Izq() 'declaracion subrutinas
Declare Sub Dere()
Portb = 1
Waitms 150
Do 'LAZO INFINITO
Call Izq() 'ir a subrutina izquierda
Call Dere() 'ir a subrutina derecha
Loop 'LAZO INFINITO
Sub Izq()
Local I As Byte
For I = 1 To 7
Rotate Portb , Left
Waitms 150
Next
End Sub
Sub Dere()
Local J As Byte
For J = 1 To 7
Rotate Portb , Right
Waitms 150
Next
End Sub
End ' FIN DEL PROGRAMA
$crystal = 1000000 'CRISTAL INTERNO DE 1 MHZ
Config Portb = Output
Dim I As Byte
Do
For I = 0 To 3
Portb = Lookup(i , Luces)
Waitms 250
Next
For I = 2 To 1 Step -1
Portb = Lookup(i , Luces)
Waitms 250
Next
Loop
End ' FIN DEL PROGRAMA
Luces:
Data &B10000001 , &B01000010 , &B00100100 , &B00011000
$crystal = 1000000
Config Portb = Output
Ddrc.0 = 0
Portc.0 = 1
Dim I As Byte
Do
If Pinc.0 = 0 Then
Portb = 1
Waitms 150
Gosub Auto
Else
Gosub Jueluces
End If
Loop
Auto:
For I = 1 To 7
Rotate Portb , Left
Waitms 150
Next
For I = 1 To 7
Rotate Portb , Right
Waitms 150
Next
Return
Jueluces:
For I = 0 To 3
Portb = Lookup(i , Luces)
Waitms 250
Next
For I = 2 To 1 Step -1
Portb = Lookup(i , Luces)
Waitms 250
Next
Return
Luces:
Data &B10000001 , &B01000010 , &B00100100 , &B00011000
$crystal = 1000000
Config Portb = Output
Dim I As Byte , Num(10) As Byte
For I = 0 To 9
Num(i + 1) = Lookup(i , Datos)
Next
I = 1
Do
Portb = Num(i)
Wait 1
Incr I
If I > 10 Then
I = 1
End If
Loop
Datos:
Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7D , &H07 , &H7F , &H67
$crystal = 1000000
Config Portb = Output
Dim I As Byte , Num(10) As Byte
For I = 0 To 9
Num(i + 1) = Lookup(i , Datos)
Next
Portb = &H3F
Wait 1
I = 10
Do
Portb = Num(i)
Wait 1
Decr I
If I < 1 Then
I = 10
End If
Loop
Datos:
Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7D , &H07 , &H7F , &H67
$crystal = 1000000 'CRISTAL INTERNO 1 mhz
Config Portb = Output 'PORTB COMO SALIDAS
Ddrc.0 = 0 'PINC.0 COMO ENTRADA DEL PULSADOR
Portc.0 = 1
Boton Alias Pinc.0 ' RENOMBRAR PINC.0 AHORA SE LLAMARA BOTON
Dim I As Byte , Num(10) As Byte 'DECLARACION DE VARIABLES Y CONTANTES DE NUMEROS 0 A 9
For I = 0 To 9
Num(i + 1) = Lookup(i , Datos)
Next
Portb = &H3F 'MOSTRAR VALOR 0
Wait 1
If Boton = 0 Then
I = 10
Else
I = 1
End If
Do
If Boton = 0 Then
Gosub Subir
Else
Gosub Bajar
End If
Portb = Num(i)
Waitms 500
Loop
Datos:
Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7D , &H07 , &H7F , &H67
Subir:
Incr I
If I > 10 Then
I = 1
End If
Return
Bajar:
Decr I
If I < 1 Then
I = 10
End If
Return
Ddrc.0=0
Portc.0=1
Boton Alias Pinc.0 Ddrc.0=0 ' pin c.0 como entrada
Portc.0=1
Ddrc.1=1 ' pin c.1 como salida
Portc.1=0
Boton Alias Pinc.0 ' alias para entrada = Pin
led alias Portc.1 ' alias para salida = port
$crystal = 1000000 'CRISTAL INTERNO 1 mhz
'***************************************************************************
' CONFIGURACION DE LOS TIMER 0
'***************************************************************************
Config Timer0 = Timer , Prescale = 8 'configuracion timer0
Stop Timer0
On Timer0 Over0 'subrutina de interrupcion del timer0
Config Portb = Output 'PORTB COMO SALIDAS
Config Portc = Output
Portc = 255
Dim I As Byte , J As Byte , Flagtmr0 As Integer , Num(10) As Byte 'DECLARACION DE VARIABLES Y CONTANTES DE NUMEROS 0 A 9
For I = 0 To 9
Num(i + 1) = Lookup(i , Datos)
Next
I = 1 : J = 1 : Flagtmr0 = 1
Timer0 = 0 'cargo valor incial del timer0
Enable Timer0 'habilito timers e interrupciones
Enable Interrupts
Start Timer0
'bucle para mostrar nuemros por los displays de 7 seg
Do
Portc = &B11111110
Portb = Num(i)
Waitms 5
Portc = &B11111101
Portb = Num(j)
Waitms 5
Loop
Datos:
Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7D , &H07 , &H7F , &H67
Over0:
If Flagtmr0 > 487 Then 'AJUSTE FINO A 1 SEGUNDO
Timer0 = 184
If Flagtmr0 > 488 Then
Incr I
If I > 10 Then
Incr J
I = 1
If J > 10 Then
J = 1
End If
End If
End If
End If
Incr Flagtmr0
If Flagtmr0 < 487 Then
Timer0 = 0
End If
Return
Hola!
Podria alguien postar algún ejemplo de interrupciones tiempo por favor?? Cómo se setea el tiempo exacto en que uno quiere que ocurra la interrupción?? Por cierto, tengo problemas con la instrucción RETURN, se supone que debe regresar a la instrucción en que estaba antes de una interrupción, pero siempre regresa al inicio del programa... Q estoy haciendo mal?
Saludos!!
una pregunta respecto al programa que usanNo, no es los mismo, Bascom es Basic y AVRstudio es Assembla.
que diferencia existe entre avr- bascom y el avr studio
las instrucciones son las mismas ?
es lo mismo programar en uno que en otro
cabe resaltar que estoy iniciando en esto y estoy
en etapa de recolectando conocimiendo de micros
gracias
jeje gracias rafa,bueno ahora ire chekeando los progrmas ke pongan en basic.. dime en el bascom hay algun menu de ayuda que te explike las instrucciones bacic ke se usan??? eske solo se assembler y hace mucho tiempo ke no practiko c o basicPues claro que en Ayuda te explica todos, con la version DEMO puede programar micro hasta 4Kbi, por ejemplo el attiny2313, y hay muchos ejemplo en la web de bascom con el attiny2313.http://www.mcselec.com/
Hola a todos!!!!Hola no te aconsejo un 240x128 porque no lo conozco, pero si entra a la pagina de AVR BASCOM Aqui (http://www.mcselec.com/index.php?option=com_content&task=category§ionid=7&id=79&Itemid=57) y buscara entre la Aplicaciones encontrara este AN #148, estudiatelo y cualquier cosas nos comenta. lo que no estoy seguro si esta la libreria en la Version DEMO. ejemplo de Bascom es dificil de subir ya que las libreria son Copyright, lo que se podia es comentar parte de la libreria o poner alguna parte como comentario, nada mas.
Ojalá me puedan ayudar. Necesito aprender a manejar un GLCD con Bascom, para empezar, me podrían recomendar el GLCD mas comun (de 240*128 sería suficiente) como el controlador que utiliza, lo que me confunde es es uso de las librerias y fuentes... (En fin ni para atras ni para adelante con eso xD)...
Si pudieran subir un ejemplo básico, se los agradecería un monton!!!!!
regfile = "m8def.dat"
$crystal = 8000000
Config Portb = Output
Semaforo Alias Portb
Semaforo = &B00000000
Declare Sub Parpadeo1()
Declare Sub Parpadeo2()
Dim X As Byte
Do
Semaforo = &B10000100
Wait 5
Gosub Parpadeo1
Semaforo = &B01000100
Wait 3
Semaforo = &B00110000
Wait 5
Gosub Parpadeo2
Semaforo = &B00101000
Wait 3
Loop
Sub Parpadeo1()
For X = 1 To 4
Semaforo = &B00000100
Waitms 200
Semaforo = &B10000100
Waitms 200
Next
End Sub
Return
Sub Parpadeo2()
For X = 1 To 4
Semaforo = &B00100000
Waitms 200
Semaforo = &B00110000
Waitms 200
Next
End Sub
Return
End
$regfile = "m16adef.dat"
$crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config Portb = Output
Semaforo Alias Portb
Semaforo = &B00000000
Declare Sub Parpadeo1()
Declare Sub Parpadeo2()
Dim X As Byte
Do
Semaforo = &B11111011
Wait 5
Gosub Parpadeo1
Semaforo = &B11111101
Wait 3
Semaforo = &B11111111
Wait 1
Semaforo = &B11111110
Wait 5
Gosub Parpadeo2
Semaforo = &B11111101
Wait 3
Semaforo = &B11111111
Wait 1
Loop
Sub Parpadeo1()
For X = 1 To 4
Semaforo = &B11111011
Waitms 200
Semaforo = &B11111111
Waitms 200
Next
End Sub
Return
Sub Parpadeo2()
For X = 1 To 4
Semaforo = &B11111110
Waitms 200
Semaforo = &B11111111
Waitms 200
Next
End Sub
Return
EndHola amigo STK500.
Me estoy apoyando sobre el datasheet, en este momento trabajo el attiny45.
Claramente dice que el conversor ADC para este chip es de 10 bits de aproximaciones sucesivas.
El montaje, si lo tengo en protoboard y así hago la comparación en proteus, lógico que proteus obvia muchas cosas. Lo curioso es que los tres ADC restantes trabajan bien y barren de 0 A 5voltios, mientras que el ADC0, no lo hace.
No tengo el código a mano, pero te lo subo después.
$regfile = "m328pdef.dat"
$crystal = 8000000
$baud = 9600
$hwstack = 40
$swstack = 16
$framesize = 32
Dim Volt As Single
Dim V As String * 4
Dim Aux1 As Word
Dim B As Byte
Config Portc = Output
Config Kbd = Portb
Do
B = Getkbd()
If B < 16 Then
Print B
End If
Loop