/*------------------------------------------------------------------- ** ** Soluciones del examen de Programación de Sistemas y Dispositivos ** Curso 2016-17, Convocatoria de Febrero, 3 de febrero de 2017 ** **-----------------------------------------------------------------*/ /*------------------------------------------------------------------- ** Ejercicio 1 **-----------------------------------------------------------------*/ #include #include #include #include #include #include void timer0_isr( void ) __attribute__ ((interrupt ("IRQ"))); volatile boolean flag; volatile uint8 scanCode; void main( void ) { sys_init(); uart0_init(); timers_init(); keypad_init(); flag = FALSE; timer0_open_ms( timer0_isr, 20, TIMER_INTERVAL ); while( 1 ) if( flag ) { uart0_puts( "\nScancode: 0x" ); uart0_puthex( scanCode ); flag = FALSE; } } void timer0_isr( void ) { static uint8 lastScanCode = 255; scanCode = keypad_scan(); if( scanCode != lastScanCode && scanCode != KEYPAD_FAILURE ) { lastScanCode = scanCode; flag = TRUE; } I_ISPC = BIT_TIMER0; } /*------------------------------------------------------------------- ** Ejercicio 2 **-----------------------------------------------------------------*/ #include #include fix16 fix_convert( fix16 number, uint8 n, uint8 m ) { fix32 aux; if( n >= m ) return number >> (n-m); else { aux = number << (m-n); if( aux > MAX_INT16 ) return MAX_INT16; else if ( aux < MIN_INT16 ) return MIN_INT16; } } /*------------------------------------------------------------------- ** Ejercicio 3 **-----------------------------------------------------------------*/ #include #include extern uint8 font[]; void lcd_putchar_xsize( uint16 x, uint16 y, uint8 color, char ch, uint8 size ) { uint8 row, col; uint8 *bitmap; bitmap = font + ch*16; for( row=0; row<16*size; row++) for( col=0; col<8*size; col++) if( bitmap[row/size] & (0x80 >> col/size) ) lcd_putpixel( x+col, y+row, color ); else lcd_putpixel( x+col, y+row, WHITE ); } /*------------------------------------------------------------------- ** Ejercicio 4 **-----------------------------------------------------------------*/ #include #include void set_mclk( uint8 numMHz ) { if( numMHz >= 20 && numMHz <= 66 ) PLLCON = ((numMHz-8) << 12) | (2 << 4) | (1); }