Академический Документы
Профессиональный Документы
Культура Документы
LABORATORIO DE ARQUITECTURA DE
COMPUTADORAS
LABORATORIO N 2
TEMA:
TIMER 8254
CODIGO
HORARIO
APELLIDOS Y NOMBRES
PC
FECHA
OBSERVACIONES
Noviembre 2014
NOTA
TEMPORIZADOR (TIMER)
Revisin de conceptos tericos
do
{
do
{
outportb( 0x43, 0xE8 );
pin_out = inportb( 0x42 ) >> 7;
} while( pin_out == 0 );
do
{
outportb( 0x43,0xE8);
pin_out = inportb( 0x42 ) >> 7;
} while( pin_out == 1 );
printf( "\r%02d:%02d:%02d", h, m, s );
} while( !kbhit() );
nibble = inportb( 0x61 ) & 0xFE;
outportb( 0x61, nibble );
/*Se deshabilita el gate del contador 2*/
}
return 0;
Para VisualC++
/**********************************************************************
PROGRAMA QUE PRESENTA UN RELOJ DE TIEMPO REAL QUE SE VISUALIZA EN LA
ESQUINA SUPERIOR IZQUIERDA DE LA PANTALLA. SE UTILIZA EL TIMER 8254
COMO BASE DE TIEMPO.
**********************************************************************/
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "winio.h"
int main( void )
{
unsigned char nibble;
int h, m, s, pin_out;
int cuenta, veinteava=0;
bool bResult;
// Call InitializeWinIo to initialize the WinIo library.
bResult = InitializeWinIo();
if( ! bResult)
{
printf("Error during initialization of WinIo.\n");
return 1;
}
printf( "Hora, minutos y segundos actuales?" );
scanf( "%d%d%d", &h, &m, &s);
/* Programacion del timer */
cuenta = 59659;
_outp( 0x43, 0XB6 );
nibble = cuenta;
_outp( 0x42, nibble );
nibble = cuenta >> 8;
_outp( 0x42, nibble );
nibble = _inp( 0x61 ) | 0x01;
_outp( 0x61, nibble );
/* Fin programacin del timer */
do
{
do
{
_outp( 0x43, 0xE8 );
pin_out = _inp( 0x42 ) >> 7;
} while( pin_out == 0 );
do
{
printf( "\r%02d:%02d:%02d", h, m, s );
} while( !_kbhit() );
nibble = _inp( 0x61 ) & 0xFE;
_outp( 0x61, nibble );
return 0;
PRACTICA
Escribir un programa que implemente un pequeo piano con las teclas A, S, D,
F, G, H, J, K para emitir una escala completa (de DO a DO). Cada nota se
emitir por un intervalo de 0.5 segundo luego de lo cual se dejar de emitir
dicha nota. Si se presiona una segunda tecla antes que termine de emitirse el
sonido de la anterior, se emitir inmediatamente la nueva nota durante el
tiempo que le corresponde (cancelando la anterior).
#include
#include
#include
#include
void
void
void
void
void
void
void
<windows.h>
<stdio.h>
<conio.h>
"winio.h"
ConfigT0( 40 );
DesactivaOndaT2aParlante();
ActivaT2();
while(1)
{
if( kbhit() )
{
c = getch();
if( c == 27 )
{
break;
}
/*40 Hz*/
/*Parlante no emite ningn tono*/
/*T2 listo para trabajar*/
{
if( c == Tecla[i] )
break;
}
if( i != 8 )
{
ConfigT2( Frec[i] );
/* Configurar tono segn tecla presionada..*/
ActivaOndaT2aParlante();/*... activar parlante... */
Cont = 20;
/*... 20 pulsos = 0.5 segundo */
}
}
if( Cont != 0 )
{
Paso25ms();
Cont--;
if( Cont == 0 )
/*... y si se ha completado la cuenta... */
DesactivaOndaT2aParlante(); /*... apagar el parlante */
}
}
DesactivaOndaT2aParlante();
DesactivaT2();
// When you're done using WinIo, call ShutdownWinIo
ShutdownWinIo();
return 0;
}
void ConfigT0( int Frec )
{
_outp(0x43,0x36);
_outp(0x40, 1193182/Frec );
_outp(0x40, (1193182/Frec)>>8 );
}
void ConfigT2( int Frec )
{
_outp(0x43,0xB6);
_outp(0x42, 1193182/Frec );
_outp(0x42, (1193182/Frec)>>8 );
}
void Paso25ms( void )
{
do
{
_outp(0x43,0xE2);
} while( (_inp(0x40)>>7) == 0);
do
{
_outp(0x43,0xE2);
} while( (_inp(0x40)>>7) == 1);
}
void ActivaT2 ( void )
{
_outp(0x61,_inp(0x61)|0x01);
}
void DesactivaT2 ( void )
{
_outp(0x61,_inp(0x61) & ~0x01);
}
void ActivaOndaT2aParlante( void )
{
_outp(0x61,_inp(0x61)|0x02);
}
void DesactivaOndaT2aParlante( void )
{
_outp(0x61,_inp(0x61) & ~0x02);
}