; SISTEMAS INFORMATICOS 2000/2001 ; ORGANO ELECTRONICO ; Antonio Ortiz Pineda ; Julio Esteban Fern ndez ; Miguel Angel Rojas ; utilizamos caracter¡sticas del 8051 $MOD51 $TITLE (ORGANO) $DATE (19-Jun-01) ;****************************************************************** ; Definici¢n de macros guardarest MACRO push PSW push ACC push DPH push DPL ENDM recuperarest MACRO pop DPL pop DPH pop ACC pop PSW ENDM ;****************************************************************** ; CONSTANTES NECESARIAS ; ESTADO MICRO DirEstadoMicro EQU 0FFFFh ; CONFIRMAR INT1 DirConfINT EQU 0FFFFh ; PS2 DirRegEstadoPS2 EQU 0FF00h BufferLlenoPS2 EQU 00000001b HayDatosPS2 EQU 00000010b DesbordPS2 EQU 00000100b BufLlenoDesbPS2 EQU 00000101b DirRegControlPS2 EQU 0FF00h HabilitarINTPS2 EQU 00000001b DeshabilitarINTPS2 EQU 00000000b DirRegDatosPS2 EQU 0FF01h ; VGA DirRegEstadoVGA EQU 0FF10h ColorVGA EQU 00000001b SelMemRefr EQU 00000010b EncenderVGA EQU 00000100b BlankVertVGA EQU 00001000b BufferLlenoVGA EQU 00010000b ErrorEscrituraVGA EQU 00100000b DirRegControlVGA EQU 0FF10h ; controla color,seleccionar tipo de memoria (refresco/pixel) y encenderVGA ; en los mismos bits que el registro de estado DirRegDirAltaVGA EQU 0FF11h ; si seleccionada mem.refresco -> 000y4y3y2y1y0 ;(coordenada y carater a escribir) ; si seleccionada mem.pixels -> 0c6c5c4c3c2c1c0 ;(caracter cuyo pixel vamos a escribir) DirRegDirBajaVGA EQU 0FF12h ; si seleccionada mem.refresco -> 000x4x3x2x1x0 ;(coordenada x caracter a escribir) ; si seleccionada mem.pixels -> 0y2y1y0x3x2x1x0 ;(pixel que vamos a escribir) ; escribir en este para escribir en memoria VGA DirRegDatosVGA EQU 0FF13h ; si seleccionada mem.refresco -> 0c6c5c4c3c2c1c0 ;(codigo del caracter) ; si seleccionada mem.pixels -> 00RRGGBB ;(codigo RGB) ; limites de 0 - 29 DirLimInfXVGA EQU 0FF14h DirLimSupXVGA EQU 0FF15h DirLimInfYVGA EQU 0FF16h DirLimSupYVGA EQU 0FF17h ; CODEC DirRegEstadoCODEC EQU 0FF20h BufferLlenoCODEC EQU 00000001b HayDatosCODEC EQU 00000010b DesbordCODEC EQU 00000100b BufLlenoDesbCODEC EQU 00000101b DirRegDatosCODEC EQU 0FF20h ; datos a enviar -> 0d2d1d0n3n2n1n0 ; siendo d2d1d0->duracion ; siendo n3n2n1n0->frec.nota ; ALEA -> generador de numeros aleatorios DirALEA EQU 0FF30h ; constantes de color ; FONDO CF EQU 00110000b ; NUMERO CN EQU 00000011b ;****************************************************************** ; SEGMENTO DE DATOS que empieza en 08h (R0-R7 mapeados,memoria de bits) ; importante no superar la barrera de 80h porque ; invadiriamos el espacio reservado a los registros DSEG AT 08H ORG 08H ; reservamos 30h bytes para pila, sera suficiente pila: DS 30h ; recibido F0 de tecla soltada 1->si 0->no recibidoF0: DS 1 ; bloqueo, indica si el teclado esta bloqueado ; el teclado se bloquea cuando se pulsa una tecla ; y se desbloquea cuando se suelta bloqueado: DS 1 ;****************************************************************** ; PARAMETROS para la funcion dibujarCaracter carYDibujarCaracter: DS 1 carXDibujarCaracter: DS 1 codigoDibujarCaracter: DS 1 ;****************************************************************** ; PARAMETROS para la funcion enviarSonido frecSonido: DS 1 tiempoSonido: DS 1 ;****************************************************************** ; a partir de aqui no se toca,reservado registros internos ORG 080h ; SEGMENTO DE CODIGO CSEG AT 0H ;saltamos a c¢digo principal jmp MAIN ; rutina de tratamiento de interrupcion para el INT0 ; (despertar micro y teclado) ORG 3H jmp RUT_INT0 ; rutina de tratamiento de interrupcion para el TIMER0 ORG 0BH jmp RUT_TIMER0 ; rutina de tratamiento de interrupcion para el INT1 (dormir micro) ORG 13H jmp RUT_INT1 ; rutina de tratamiento de interrupcion para el TIMER1 ORG 1BH jmp RUT_TIMER1 ; rutina de tratamiento de interrupcion para el puerto serie ORG 23H jmp RUT_SERIE ; rutina de tratamiento de interrupcion para el TIMER2 ORG 2BH jmp RUT_TIMER2 ;****************************************************************** ; RUTINA PRINCIPAL MAIN: ; inicializo pila mov SP,#pila ; INICIALIZO VGA->la apago mov DPTR,#DirRegControlVGA mov A,#0 movx @DPTR,A ; INICIALIZACION INTERRUPCIONES Y CONTADORES ; preparo interrupciones ; interrupciones controladas por IE (bit PCT=1) ; PCT --- PT2 PS PT1 PX1 PT0 PX0 ; 1 0 0 0 0 0 0 0 mov IP,#10000000b ; habilito interrupciones INT1 Y INT0 ; EA --- ET2 ES ET1 EX1 ET0 EX0 ; 1 0 0 0 0 1 0 1 mov IE,#10000101b ; habilito INT1,INT0 por flanco (IT1=1,IT0=1) ; TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 ; 0 0 0 0 0 1 0 1 mov TCON,#00000101b ; modo de los contadores mediante TMOD ; contador 0 en modo de 16 bits (M1M0=01) con reloj interno (CT=0) ; y sin GATE (GATE=1) ; contador 1 en modo de 16 bits (M1M0=01) con reloj interno (CT=0) ; y sin GATe (GATE=1) ; CONTADOR 1 CONTADOR 0 ; GATE CT M1 M0 GATE CT M1 M0 ; 1 0 0 1 1 0 0 1 mov TMOD,#10011001b ;************************************************************* mov recibidoF0,#0 mov bloqueado,#0 mov tiempoSonido,#4 ;****************************************************************** ; me paro aqui: jmp aqui ;****************************************************************** ; Procedimiento para dibujar un caracter en la VGA : ; Parametros utiizados (que se pasan por memoria) por esta funcion; ; carYDibujarCaracter: coordenadaY caracter a modificar ; carXDibujarCaracter: coordenadaX caracter a modificar ; codigoDibujarCaracter: codigo del nuevo caracter dibujarCaracter: ; seleccionamos memoria de refresco mov DPTR,#DirRegControlVGA mov A,#00000111b movx @DPTR,A ; podemos escribir en la VGA? mov DPTR,#DirRegEstadoVGA poderEscrVGA: movx A,@DPTR anl A,#BufferLlenoVGA jnz poderEscrVGA ; ya podemos escribir mov DPTR,#DirRegDirAltaVGA mov A,carYDibujarCaracter movx @DPTR,A mov DPTR,#DirRegDirBajaVGA mov A,carXDibujarCaracter movx @DPTR,A mov DPTR,#DirRegDatosVGA mov A,codigoDibujarCaracter movx @DPTR,A finDC: ; volvemos ret ;****************************************************************** ; Procedimiento para enviar un sonido al CODEC : ; Parametros utiizados (que se pasan por memoria) por esta funcion; ; frecSonido: frecuencia de la nota ; tiempoSonido: duracion de la nota enviarSonido: mov DPTR,#DirRegEstadoCODEC ; esperamos a enviar sonido esperarSonido: movx A,@DPTR anl A,#BufLLenoDesbCODEC jnz esperarSonido ; enviamos sonido mov DPTR,#DirRegDatosCODEC ; filtramos frecuencia por si acaso mov A,frecSonido anl A,#00001111b mov frecSonido,A ; preparamos nota mov A,tiempoSonido RL A RL A RL A RL A anl A,#11110000b add A,frecSonido movx @DPTR,A ret ;****************************************************************** ; RUTINA DE TRATAMIENTO DE INTERRUPCION PARA EL INT0 ; DESPERTAR AL MICRO Y ATENDER PS2 RUT_INT0: ; deshabilito todas las interrupciones menos INT1 mov IE,#10000100b ; guardo estado de la maquina guardarEST ; tratamiento del teclado ; primero vemos si hemos pulsado tecla mov DPTR,#DirRegEstadoPS2 movx A,@DPTR anl A,#HayDatosPS2 jz finINTPS2Prev jmp empezarTratarTecla finINTPS2Prev: jmp finINTPS2 empezarTratarTecla: ; hay tecla,pues la leemos mov DPTR,#DirRegDatosPS2 movx A,@DPTR ; guardamos en R0 mov R0,A ; es F0? clr C subb A,#11110000b jnz noF0 ; si es F0, lo marcamos mov recibidoF0,#1 jmp finINTPS2 noF0: ; si antes se habia recibido F0, desbloqueamos mov A,recibidoF0 jz tratarTecla mov recibidoF0,#0 mov bloqueado,#0 jmp finINTPS2 tratarTecla: mov recibidoF0,#0 mov A,bloqueado ; si estamos bloqueados, ni caso jz frec0 jmp finINTPS2 ; tecla A->frec 0 frec0: mov A,R0 clr C subb A,#00011100b jnz frec1 ; frec0 mov frecSonido,#0 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla S->frec 1 frec1: mov A,R0 clr C subb A,#00011011b jnz frec2 ; frec1 mov frecSonido,#1 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla D->frec 2 frec2: mov A,R0 clr C subb A,#00100011b jnz frec3 ; frec2 mov frecSonido,#2 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla F->frec 3 frec3: mov A,R0 clr C subb A,#00101011b jnz frec4 ; frec3 mov frecSonido,#3 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla G->frec 4 frec4: mov A,R0 clr C subb A,#00110100b jnz frec5 ; frec4 mov frecSonido,#4 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla H->frec 5 frec5: mov A,R0 clr C subb A,#00110011b jnz frec6 ; frec5 mov frecSonido,#5 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla J->frec 6 frec6: mov A,R0 clr C subb A,#00111011b jnz frec7 ; frec6 mov frecSonido,#6 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla K->frec 7 frec7: mov A,R0 clr C subb A,#01000010b jnz frec8 ; frec7 mov frecSonido,#7 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla L->frec 8 frec8: mov A,R0 clr C subb A,#01001011b jnz frec9 ; frec8 mov frecSonido,#8 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla ¥->frec 9 frec9: mov A,R0 clr C subb A,#01001100b jnz frec10 ; frec9 mov frecSonido,#9 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla {->frec 10 frec10: mov A,R0 clr C subb A,#01010010b jnz frec11 ; frec10 mov frecSonido,#10 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla }->frec 11 frec11: mov A,R0 clr C subb A,#01011101b jnz frec12 ; frec11 mov frecSonido,#11 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tecla INTRO->frec 12 frec12: mov A,R0 clr C subb A,#01011010b jnz tiempoMenos ; frec12 mov frecSonido,#12 call enviarSonido mov bloqueado,#1 jmp finINTPS2 ; tiempoMenos tiempoMenos: mov A,R0 clr C subb A,#01111011b jnz tiempoMas dec tiempoSonido jmp finINTPS2 ; tiempoMas tiempoMas: mov A,R0 clr C subb A,#01111001b jnz finINTPS2 inc tiempoSonido jmp finINTPS2 finINTPS2: ; recupero estado de la maquina recuperarEST ; habilito INT0,INT1 mov IE,#10000101b reti ;******************************************************** ; RUTINA DE TRATAMIENTO DE INTERRUPCION PARA EL TIMER0 RUT_TIMER0: reti ;******************************************************** ; RUTINA DE TRATAMIENTO DE INTERRUPCION PARA EL INT1 ; DORMIR AL MICRO RUT_INT1: ; desactivo contador clr TR1 ; desactivar interrupciones anl IE,#01111111b ; guardo estado de la maquina guardarEST ; avisamos que int atendida mov DPTR,#DirConfINT movx @DPTR,A volverDormir: ; pongo bit ALF=1, para ponerme en estado FLOATING ; --- T32 SERR IZC P3HZ P2HZ P1HZ ALF ; 0 0 0 0 0 0 0 1 ; IOCON = 0F8h mov 0F8h,#00000001b ; duermo al micro colocandolo en modo Power Down (PD=1), ; y permito que cualquier interrupcion le despierte, continuando la ejecucion ; normal (RPD=1) ; SMOD HPD RPD --- GF1 GF0 PD IDL ; 0 0 1 0 0 0 1 0 orl PCON,#00100000b orl PCON,#00000010b ; hago una lectura -> esta el micro dormido? si es asi volvemos mov DPTR,#DirEstadoMicro movx A,@DPTR jz volverDormir ; recupero estado de la maquina recuperarEST ; activar interrupciones orl IE,#10000000b ; activo contador setb TR1 ;volvemos reti ; RUTINA DE TRATAMIENTO DE INTERRUPCION PARA EL TIMER1 RUT_TIMER1: reti ;******************************************************** ; RUTINA DE TRATAMIENTO PARA EL PUERTO SERIE RUT_SERIE: reti ;******************************************************** ; RUTINA DE TRATAMIENTO DE INTERRUPCION PARA EL TIMER2 RUT_TIMER2: reti ;****************************************************************** ; DATOS VGA ; segmento de datos en memoria externa ; pensado para inicializar memoria de pixels ; como direccionamos? ; MEMORIA DE PIXELS: 1c6c5c4c3c2c1c0y2y1y0x3x2x1x0 ; MEMORIA DE CARACTERES/REFRESCO: 100y4y3y2y1y0x4x3x211x1x0 ORG 100000000000000b ; caracter 0000000 => 0 ORG 100000000000000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100000000010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100000000100000b DB CF,CF,CN,CN,CN,CF,CN,CN,CF,CF ORG 100000000110000b DB CF,CF,CN,CN,CN,CN,CN,CN,CF,CF ORG 100000001000000b DB CF,CF,CN,CN,CF,CN,CN,CN,CF,CF ORG 100000001010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100000001100000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100000001110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0000001 => 1 ORG 100000010000000b DB CF,CF,CF,CF,CN,CN,CF,CF,CF,CF ORG 100000010010000b DB CF,CF,CF,CN,CN,CN,CF,CF,CF,CF ORG 100000010100000b DB CF,CF,CF,CF,CN,CN,CF,CF,CF,CF ORG 100000010110000b DB CF,CF,CF,CF,CN,CN,CF,CF,CF,CF ORG 100000011000000b DB CF,CF,CF,CF,CN,CN,CF,CF,CF,CF ORG 100000011010000b DB CF,CF,CF,CF,CN,CN,CF,CF,CF,CF ORG 100000011100000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100000011110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0000010 => 2 ORG 100000100000000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100000100010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100000100100000b DB CF,CF,CF,CF,CF,CF,CN,CN,CF,CF ORG 100000100110000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100000101000000b DB CF,CF,CN,CN,CF,CF,CF,CF,CF,CF ORG 100000101010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100000101100000b DB CF,CF,CN,CN,CN,CN,CN,CN,CF,CF ORG 100000101110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0000011 => 3 ORG 100000110000000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100000110010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100000110100000b DB CF,CF,CF,CF,CF,CF,CN,CN,CF,CF ORG 100000110110000b DB CF,CF,CF,CF,CN,CN,CN,CF,CF,CF ORG 100000111000000b DB CF,CF,CF,CF,CF,CF,CN,CN,CF,CF ORG 100000111010000b DB CF,CF,CF,CF,CF,CF,CN,CN,CF,CF ORG 100000111100000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100000111110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0000100 => 4 ORG 100001000000000b DB CF,CF,CF,CF,CN,CN,CN,CF,CF,CF ORG 100001000010000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100001000100000b DB CF,CF,CN,CN,CF,CN,CN,CF,CF,CF ORG 100001000110000b DB CF,CN,CN,CF,CF,CN,CN,CF,CF,CF ORG 100001001000000b DB CF,CN,CN,CN,CN,CN,CN,CN,CF,CF ORG 100001001010000b DB CF,CF,CF,CF,CF,CN,CN,CF,CF,CF ORG 100001001100000b DB CF,CF,CF,CF,CN,CN,CN,CN,CF,CF ORG 100001001110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0000101 => 5 ORG 100001010000000b DB CF,CF,CN,CN,CN,CN,CN,CN,CF,CF ORG 100001010010000b DB CF,CF,CN,CN,CF,CF,CF,CF,CF,CF ORG 100001010100000b DB CF,CF,CN,CN,CF,CF,CF,CF,CF,CF ORG 100001010110000b DB CF,CF,CN,CN,CN,CN,CN,CF,CF,CF ORG 100001011000000b DB CF,CF,CF,CF,CF,CF,CN,CN,CF,CF ORG 100001011010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100001011100000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100001011110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0000110 => 6 ORG 100001100000000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100001100010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100001100100000b DB CF,CF,CN,CN,CF,CF,CF,CF,CF,CF ORG 100001100110000b DB CF,CF,CN,CN,CN,CN,CN,CF,CF,CF ORG 100001101000000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100001101010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100001101100000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100001101110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0000111 => 7 ORG 100001110000000b DB CF,CF,CN,CN,CN,CN,CN,CN,CF,CF ORG 100001110010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100001110100000b DB CF,CF,CF,CF,CF,CF,CN,CN,CF,CF ORG 100001110110000b DB CF,CF,CF,CF,CF,CN,CN,CF,CF,CF ORG 100001111000000b DB CF,CF,CF,CF,CN,CN,CF,CF,CF,CF ORG 100001111010000b DB CF,CF,CF,CF,CN,CN,CF,CF,CF,CF ORG 100001111100000b DB CF,CF,CF,CF,CN,CN,CF,CF,CF,CF ORG 100001111110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0001000 => 8 ORG 100010000000000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100010000010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100010000100000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100010000110000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100010001000000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100010001010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100010001100000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100010001110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF ; caracter 0001001 => 9 ORG 100010010000000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100010010010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100010010100000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100010010110000b DB CF,CF,CF,CN,CN,CN,CN,CN,CF,CF ORG 100010011000000b DB CF,CF,CF,CF,CF,CF,CN,CN,CF,CF ORG 100010011010000b DB CF,CF,CN,CN,CF,CF,CN,CN,CF,CF ORG 100010011100000b DB CF,CF,CF,CN,CN,CN,CN,CF,CF,CF ORG 100010011110000b DB CF,CF,CF,CF,CF,CF,CF,CF,CF,CF END