/*------------------------------------------------------------------------------------------------------------*/ char VS10xx_INIT( void ) { // Steuerleitungen einrichten für MP3-Decoder POWER_DDR |= ( 1<<POWER ); RESET_DDR |= ( 1<<RESET ); BSYNC_DDR |= ( 1<<BSYNC ); DREQ_DDR &= ~( 1<<DREQ ); SS2_DDR |= ( 1<<SS2 ); // Steuerleitungen auf Startzustand setzen RESET_PORT |= ( 1<<RESET ); BSYNC_PORT &= ~( 1<<BSYNC ); DREQ_PORT &= ~( 1<<DREQ ); SS2_PORT |= ( 1<<SS2 ); SPI2_init(); // MP3-Decoder einschalten POWER_PORT |= ( 1<<POWER ); // 100ms warten bis Spannung stabil ist und Controller sie initialisiert hat CLOCK_delay( 1000 ); // reset the decoder CLOCK_delay(30); VS10xx_reset(HARD_RESET); CLOCK_delay(30); VS10xx_nulls(32); VS10xx_reset(SOFT_RESET); VS10xx_set_xtal (); // Wenn xtal nicht erfolgreich gesetzt ist REv.2 der Hardware vorhanden und muss per // HardwareSPI angesteuert werden if ( VS10xx_read( VS10xx_Register_CLOCKF ) != VS10xx_CLOCKF ) { hardwarespi=1; SPI0_init( SPI_HALF_SPEED ); // reset the decoder CLOCK_delay(30); if ( VS10xx_reset(HARD_RESET) == RESET_FAILED ) return( RESET_FAILED ); CLOCK_delay(30); VS10xx_nulls(32); if ( VS10xx_reset(SOFT_RESET) == RESET_FAILED ) return( RESET_FAILED ); VS10xx_set_xtal (); } // VS10xx_vol ( 200, 200 ); VS10xx_vol ( 255, 255 ); return( RESET_OK ); }
/*------------------------------------------------------------------------------------------------------------*/ unsigned int VS10xx_read( unsigned char address) { unsigned int Data; SS2_PORT &= ~( 1<<SS2 ); if ( hardwarespi == 0 ) { SPI2_ReadWrite(VS10xx_READ); SPI2_ReadWrite(address); Data = SPI2_ReadWrite(0) << 8; Data |= SPI2_ReadWrite(0); } else { SPI0_ReadWrite(VS10xx_READ); SPI0_ReadWrite(address); Data = SPI0_ReadWrite(0) << 8; Data |= SPI0_ReadWrite(0); } SS2_PORT |= ( 1<<SS2 ); //this is absolutely neccessary! CLOCK_delay(50); //wait 5 microseconds after sending data to control port return( Data ); }
/* -----------------------------------------------------------------------------------------------------------*/ void HD44780_TWI_sendCMD( char CMD ) { HD44780_TWI_Byte &= ~( 1 << HD44780_TWI_RS_PIN ); HD44780_TWI_out( CMD ); HD44780_TWI_out( CMD<<4 ); #if HD44780_DELAY_COMMAND > 0 CLOCK_delay( HD44780_DELAY_COMMAND ); #endif }
/* -----------------------------------------------------------------------------------------------------------*/ void HD44780_TWI_sendDATA( char Data ) { HD44780_TWI_Byte |= ( 1 << HD44780_TWI_RS_PIN ); HD44780_TWI_out( Data ); HD44780_TWI_out( Data<<4 ); #if HD44780_DELAY_WRITEDATA > 0 CLOCK_delay( HD44780_DELAY_WRITEDATA ); #endif }
/* -----------------------------------------------------------------------------------------------------------*/ void HD44780_TWI_init( void ) { unsigned char i; int y; HD44780_TWI_Byte = 0; // erster Reset in den 8-Bit Modus HD44780_TWI_out(HD44780_CMD_SOFT_RESET); CLOCK_delay( HD44780_DELAY_SOFT_RESET1 ); // zweiter Reset in den 8-Bit Modus HD44780_TWI_enable(); CLOCK_delay( HD44780_DELAY_SOFT_RESET2 ); // dritter Reset in den 8-Bit Modus HD44780_TWI_enable(); CLOCK_delay( HD44780_DELAY_SOFT_RESET3 ); // und jetzt endlich in den 4-Bit Modus HD44780_TWI_out( HD44780_CMD_SET_FUNCTION | HD44780_SF_4BIT ); CLOCK_delay( HD44780_DELAY_SET_4BITMODE ); // Display einstellen, 4Bit, 2 Lines und Zeichensatz 5x8 Pixel HD44780_TWI_sendCMD( HD44780_CMD_SET_FUNCTION | HD44780_SF_4BIT | // 4 Bit mode HD44780_SF_2LINES | // 2 lines HD44780_SF_5x10 ); // 5x10 // clear screen HD44780_TWI_sendCMD( HD44780_CMD_CLEAR ); // Cursor auf Homeposition setzen HD44780_TWI_sendCMD( HD44780_CMD_CURSOR_HOME ); // Display einschalten HD44780_TWI_sendCMD( HD44780_CMD_SET_DISPLAY | HD44780_SD_DISPLAY_ON /* | // display on HD44780_SD_CURSOR_ON | // show cursor HD44780_SD_BLINKING_ON */ ); // cursor blinking HD44780_TWI_row = 0; HD44780_TWI_column = 0; // fade in LCD-Backlight if ( TWI_SendAddress( HD44780_TWI_ADDR , TWI_WRITE ) == TRUE ) { for( y = 0 ; y < 128 ; y++ )// Backlight auf 100% dimmen { for ( i = 0 ; i < 128 ; i++ ) { if( i <= y) HD44780_TWI_Byte &= ~( 1 << HD44780_TWI_BL_PIN ); else HD44780_TWI_Byte |= ( 1 << HD44780_TWI_BL_PIN ); TWI_Write( HD44780_TWI_Byte ); } } TWI_SendStop(); } HD44780_TWI_Byte &= ~( 1 << HD44780_TWI_BL_PIN ); }
/* -----------------------------------------------------------------------------------------------------------*/ void KS0073_TWI_init( void ) { unsigned char i; int y; KS0073_TWI_Byte = 0; // erster Reset in den 8-Bit Modus KS0073_TWI_out(HD44780_CMD_SOFT_RESET); CLOCK_delay( HD44780_DELAY_SOFT_RESET1 ); // zweiter Reset in den 8-Bit Modus KS0073_TWI_enable(); CLOCK_delay( HD44780_DELAY_SOFT_RESET2 ); // dritter Reset in den 8-Bit Modus KS0073_TWI_enable(); CLOCK_delay( HD44780_DELAY_SOFT_RESET3 ); // und jetzt endlich in den 4-Bit Modus und 'RE-Bit ein b00101100 KS0073_TWI_out(HD44780_CMD_SET_FUNCTION | HD44780_SF_4BIT); // RE:1 CLOCK_delay( HD44780_DELAY_SET_4BITMODE ); KS0073_TWI_sendCMD(HD44780_CMD_SET_FUNCTION | HD44780_SF_4BIT | HD44780_SF_2LINES | KS0073_RE_ON); // Display für KS0073 einstellen b00001001 KS0073_TWI_sendCMD(KS0073_CMD_EXT_FUNCTION | HD44780_SF_5x7 | // 5-dot-Font KS0073_4LINES); // 4-line display // RE:Bit wieder auf 0 setzen b00101000 KS0073_TWI_sendCMD(HD44780_CMD_SET_FUNCTION | HD44780_SF_4BIT | HD44780_SF_2LINES| KS0073_RE_OFF); // clear screen KS0073_TWI_sendCMD( HD44780_CMD_CLEAR ); //Display ausschalten KS0073_TWI_sendCMD(HD44780_CMD_SET_DISPLAY | HD44780_SD_DISPLAY_OFF); // Entry Mode KS0073_TWI_sendCMD(HD44780_CMD_SET_ENTRY | HD44780_SE_INCREASE); // Display clear cursor home KS0073_TWI_sendCMD( HD44780_CMD_CLEAR ); // Cursor auf Homeposition setzen KS0073_TWI_sendCMD( HD44780_CMD_CURSOR_HOME ); // Display einschalten KS0073_TWI_sendCMD( HD44780_CMD_SET_DISPLAY | HD44780_SD_DISPLAY_ON /* | // display on HD44780_SD_CURSOR_ON | // show cursor HD44780_SD_BLINKING_ON */ ); // cursor blinking KS0073_TWI_row = 0; KS0073_TWI_column = 0; // fade in LCD-Backlight if ( TWI_SendAddress( KS0073_TWI_ADDR , TWI_WRITE ) == TRUE ) { for( y = 0 ; y < 128 ; y++ )// Backlight auf 100% dimmen { for ( i = 0 ; i < 128 ; i++ ) { if( i <= y) KS0073_TWI_Byte &= ~( 1 << KS0073_TWI_BL_PIN ); else KS0073_TWI_Byte |= ( 1 << KS0073_TWI_BL_PIN ); TWI_Write( KS0073_TWI_Byte ); } } TWI_SendStop(); } KS0073_TWI_Byte &= ~( 1 << KS0073_TWI_BL_PIN ); }