TODOPIC
Microcontroladores PIC => Lenguaje Basic para microcontroladores PIC => Mensaje iniciado por: stk500 en 25 de Septiembre de 2008, 03:04:14
-
Hola Amigos!
Hace tiempo que estoy estudiando Picbasic pro y me quiero hacer una matrix que active los canales que yo le envie, el transmisor es con el protocolo DMX512 osea 250000 Baudrate hasta aqui lo tengo claro, quiero usar el protocolo I2C para implementar los Pulsadores y no se si usar un PCF8574 o PCA9555, quiero usar el pic16F877 de 40 pines , quizas alguien me pueda ayudar como implementar una matrix de pulsadores I2C? o quizas hay otras manera de hacerlo? quiero saber vuestras opinion
Saludo
-
Hola stk500
Si no entiendo mal lo que quieres hacer es una matriz de led's (luces) y desde cierta distancia activar los distintos canales mediante DMX, osea puntualmente el led (o luz) que tu quieras es asi? de ser asi no creo que necesites si o si I2C, ahora bien, tendria que ser un pulsador por cada led? aguardo respuestas para entender un poco mejor lo que quieres.-
saludos
Hernán
-
Muchas gracias Hernan por tu interes, no solo matrix de luces sino una matrix de pulsadores ON/OFF de 64 Tecla, cada tecla es una canal preselecionados, bien decia de usar I2C y con unos PCA9555 hacer la matrix, no quiero usar LED aqui pero quiero poner LCD y una EEPROM y tambien coger 3 pines de pic para hcaer Opciones que memorizaras la preseleciones de preferencia de algunos Eventos
Lo que no lo tengo claro es la implementacion de los pines como matrix de pulsadores con un PCA9555, llevo dias buscando informacion en Google y no he encontrado nada :x quizas Usted tiene ideas como puede implementar.
Te agradezco todas las ayudas que me pueda aportar, Gracias
Saludo
-
hola compadre lo que pretendes implementar es un teclado matriarcal no se si ya allas trabajado alguna rutina de estas en pbp , si no lo as echo mi humilde opinión es que primero estudies una rutina de estas con el pic que vas a utilizar para que entiendas como trabaja la matriz te recomiendo que implementes una matriz 4x4 que te dará 16 teclas muy bueno para comenzar.
Si ya as trabajado con un teclado matriarcal lo que te resta es leer la data del expanzor de puertos que quieras utilizar para configurar cuales serán los puertos de entrada y salida y en tu rutina de teclado (rutina de teclado 4x4) sustituir las instrucciones de escritura y lectura de los puertos del pic por las instrucciones 12c read write del chip expanzor pues bueno mas omenos esta es la idea cualquier cosa por aquí andamos
-
:g) gracias Sandra por tu sugerencia, pero eso ya lo se , ¿pero como leo con el protocolo la data del expansor? si es como Usted dice usando la configuracion normal como si fuera los puerto de un pic mas o menos creo es asi
Device 16F876A
XTAL 20
Symbol SDA = PORTB.1
Symbol SCL = PORTB.2
Symbol DIR_IN = %01000010 'Establece la direccion del pcf8574 de entrada de datos
Symbol DIR_OUT = %01000000 'Establece la direccion del pcf8574 de salida de datos
Dim DATOS As Byte
DelayMS 500 'Retardo de 500ms para estabilizar
DEFINICION DE VARIABLES
DIM fila AS BYTE 'fila del teclado
DIM columna AS BYTE 'columna del teclado
DIM tecla AS BYTE 'Variable para el valor de la tecla
DIM salida AS BIT
DIM retardo AS BYTE 'retardo para impedir rebotes
'DEFINICION DE LOS PINES DE ENTRADA/SALIDA.
ADCON1 = 7 'PORTA y PORTE como I/O digitales
TRISA=%00000000 'Los pin PORTA son salidas
TRISB=%11111111 'Los pin son entradas.
TRISC=%00000000 'Los pin son SALIDAS.
TRISD=%00000000 'Los pin son SALIDAS.
aunque me gustaria saber si alguien sabe como direcionar las tecla para transmitirla.
Saludo
-
Haber señor creo que usted no me entendió esta es una rutina para escanear una matriz de teclas solo abría que reemplazar por las instrucciones 12c espero que así se entienda mejor
' Program KEYPAD16.BAS
' *************************************************************
' * For use with EXPERIMENTING WITH THE PICBASIC PRO COMPILER *
' * *
' * This source code may be freely used within your own *
' * programs. However, if it is used for profitable reasons, *
' * please give credit where credit is due. *
' * And make a reference to myself or Rosetta Technologies *
' * *
' * Les. Johnson *
' *************************************************************
'
' Scan a 16-button keypad using the first four bits of PortA and PortB
' This is the same routine as ASM_KEY, but written in basic.
Include "Modedefs.Bas"
' ** Setup the Crystal Frequency, in MJz **
Define OSC 4 ' Set Xtal Frequency
' ** Setup the Debug Defines **
Define DEBUG_REG PORTB ' Debug PortB
Define DEBUG_BIT 7 ' *** Debug pin Bit-7 ***
Define DEBUG_BAUD 9600 ' *** Debug Baud Rate ***
Define DEBUG_MODE 1 ' Set Serial Mode 1=Inverted
Define DEBUG_PACING 300 ' Delay 'in Us' between characters sent
' ** Define LCD Control Constants **
I Con 254 ' Control Byte
Clr Con 1 ' Clear the display
Line1 Con 128 ' Point to beginning of line 1
Line2 Con 192 ' Point to beginning of line 2
Line3 Con 148 ' Point to beginning of line 3
Line4 Con 212 ' Point to beginning of line 4
Cgram Con 64 ' Point to Cgram within LCD
' ** Declare the Variables **
K_Flag Var Bit
Key Var Byte
Debounce Var Bit ' Flag to indicate a keypress.
D_Flag Var Bit ' Debounce flag used by Inkeys.
Debug I,Clr:Pause 30 ' Clear the LCD
Inc_D_Flag=0 ' Reset the debounce flag, prior to calling the subroutine
Main:
GoSub Keyscan
Debug I,Line1,#Key," "
GoTo Main
' This subroutine Scans the 16 button keypad and returns the key pressed in "KEY"
' If no key is pressed the value returned is 128.
' It also returns a Bit-Flag called DEBOUNCE which is 1 if a key is still in use
' And 0 if not. This acts as a debounce for the Keypad.
Keyscan:
Debounce=1 ' Setup the initial value for Debounce
Key=0 ' Clear the variable KEY, prior to scanning
TRISA.0=0:TRISA.1=0 ' Make the first four bits of PortA Outputs
TRISA.2=0:TRISA.3=0
TRISB.0=1:TRISB.1=1 ' Make the first four bits of PortB inputs
TRISB.2=1:TRISB.3=1
OPTION_REG.7=0 ' Enable Internal PortB Pullup Resistors
PORTA=%0111 ' Pull the fourth row line LOW
GoSub Scancol ' Scan the columns
If K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTA=%1011 ' Pull the third row line LOW
GoSub Scancol ' Scan the columns
If K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTA=%1101 ' Pull the second row line LOW
GoSub Scancol ' Scan the columns
If K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTA=%1110 ' Pull the first row line LOW
GoSub Scancol ' Scan the columns
If K_Flag=1 Then GoTo Map ' If a key is pressed then map it
D_Flag=0 ' No key pressed, so Reset debounce flag
Debounce=0 ' No key pressed, so Reset key Debounce flag
GoTo Exit ' Exit from the subroutine
' Do the following code if a key has been pressed
Map: If D_Flag=1 Then Exit ' Already responded to this press, so exit
D_Flag=1 ' Set Debounce flag
Debounce=0 ' Reset key Debounce flag
Exit: LookUp Key,[15,7,4,1,0,8,5,2,14,9,6,3,13,12,11,10,128],Key ' Map of the keypad legends
Return ' Exit from the subroutine
' This subroutine scans the columns
' The bit, K_Flag returns a 1 if a key is pressed, and 0 if no key pressed
' Also, if no key is pressed the variable KEY will return with the value of 16
Scancol:
K_Flag=1 ' Set K_Flag initially to 1
If PORTB.0=0 Then S_Exit ' Return if a key on the first column is pressed
Key=Key+1 ' Else increment KEY, and try another row
If PORTB.1=0 Then S_Exit ' Return if a key on the second column is pressed
Key=Key+1 ' Else increment KEY, and try another row
If PORTB.2=0 Then S_Exit ' Return if a key on the third column is pressed
Key=Key+1 ' Else increment KEY, and try another row
If PORTB.3=0 Then S_Exit ' Return if a key on the fourth column is pressed
Key=Key+1 ' Else increment KEY, KEY now equals 16
K_Flag=0 ' Set the K_Flag to indicate no key pressed
S_Exit: Return ' And exit the subroutine
-
:g) la que no entiende es usted :D y como tu dice remplazar la Rutina es lo que deseo saber, Dame un picolo Ejemplo :g)
Gracias nena
-
Pues mira ahí si va a estar medio en chino :( por que nunca lo e realizado al igual que tu tengo la idea que sustituyendo las llamadas a los puertos debe funcionar así que en esto tendrás que ser pionero cuando tengas el integrado abra que comenzar a realizar pruebas
Asiendo algo como un eco lo que salga por un puerto que lo reciba otro, luego que tengas eso ya esta mas fácil el asunto.
Dime por fin por cual expanzo de puertos te as decidido para echarle un ojo a la data.
Ase mucho mire un ejemplo de aplicación donde hacían esto es un expanzo de texas instruments de 16 puertos pero no recuerdo la matricula del integrado :x tendrás que echarte un clavado en la pagina de texas
Ciento no poder ayudarte más pero de momento no se me ocurre otra cosa :g)