You are on page 1of 24

Audio system with iPod interface

Design manual
Rev. 13 — 16, October 2006 Design manual

Document information Info Keywords Abstract Content LPC900, iPod HW and SW document for the iPod demo board

NXP Semiconductors

Audio system with iPod interface
Design manual

Revision history Rev 01 Date 20061016 Description Initial Version

Contact information
For additional information, please visit: http://www.nxp.com For sales office addresses, please send an email to: sales.addresses@www.nxp.com
© NXP B.V. 2006. All rights reserved.

Rev. 13 — 16, October 2006

2 of 24

13 — 16. iPod communication module 3. 2006. LCD display module The detail will be discussed in later chapter. October 2006 3 of 24 . Driver Keyboard Scan Algorithm LCD Display Driver Character LIb LCD Display 320*240 DOTS Key Board LCP936 The software can be divided into three modules. All rights reserved. design and implementation.2 308 7.2 Software framework iPod iPod Comm. The source code is passed in Keil uVision2. 1. flowchart.1 Introduction We discussed the software of the “Audio system with iPod interface” demo board. Rev. Keyboard scan module 2. The following table shows the memory consumption.V.5 1. Memory Type data xdata flash Size(Byte) 128 512 16K Consumption (Byte) 67. © NXP B. including the framework. Introduction of system software 1.NXP Semiconductors Audio system with iPod interface Design manual 1.

All rights reserved. Software design and implementation 2.1 Scan method © NXP B.2 Keyboard scan module 2. 13 — 16.1 Software flowchart 2. October 2006 4 of 24 .NXP Semiconductors Audio system with iPod interface Design manual 2. 2006. Rev.V.2.

If KEY3 is low.2 Source code #include ". 2006. k1-k10. K3 is pressed. data uint8 key_code_tmp. If KEY1 to KEY4 are all high. the related I/O will be low level.. 13 — 16. 2. 5. 2. © NXP B.V. data uint8 scan_in_value. If a key pressed. 3.h" #define SCAN_DELAY_TIME 5 // set keyboard satus #define SET_KB_STATUS(value) \ { \ (P2 = (P2 & 0xc3) | (value << 2 )).NXP Semiconductors Audio system with iPod interface Design manual There are 10 keys in the demo board. Set KEY1 to KEY4 to low. If KEY2 is low. high. If KEY1 is low. K6 is pressed. We combine the 4 bit writing to and reading from the I/O port and get a one-byte key scan code. K3. neither of K1. October 2006 5 of 24 . 4. (P2>>2 & 0xF) uint8 KB_Scan(void) { data uint8 scan_out_value. high (0111) then detect KEY2 to KEY4. Set KEY1 to KEY4 to high level then detect KEY1 to KEY4. Rev. K1 is pressed.\include\kb. KEY1 to KEY4 are linked to the I/O port of LPC936. All rights reserved.2. high. 1. K6 and K10 is pressed and continues to scan. \ } // retrieve keyboard status #define GET_KB_STATUS // the key code last time data uint8 key_code_buf = KEY_INVALID.

return KEY_INVALID.i++) { scan_out_value = ((flag ^ 0xff)>>2) & 0x0f. All rights reserved. 13 — 16. // 0000 0010 data uint8 i.i<4. } key_code_tmp = key_code_buf.. } © NXP B.NXP Semiconductors Audio system with iPod interface Design manual data uint8 flag = 0x02. if (scan_out_value != scan_in_value) //some key pressed { // output value as high half byte // input value as low half byte // combine two half bytes and get one-byte key code key_code_buf = scan_in_value | (scan_out_value<<4). return key_code_tmp. 2006. Rev.V. #endif scan_in_value = GET_KB_STATUS.5] SET_KB_STATUS(scan_out_value). for (i=0. #if SCAN_DELAY_TIME > 0 DELAY_CPU_CYCLE(SCAN_DELAY_TIME). // output low 4 bits to P2[2. October 2006 6 of 24 . } flag <<= 1. if (key_code_tmp != KEY_INVALID) key_code_buf = KEY_INVALID.

2 iPod message data structure // message type for Request/Response Structure typedef struct { //uint8 header[2].1 framework The communication module will use LPC900 UART to send command to and receive feedback from iPod. 13 — 16. uint8 mode. // 0xff.3.NXP Semiconductors Audio system with iPod interface Design manual 2. //size of mode+command+parameter Rev. All rights reserved. 0x55 uint8 length. 2.3. uint8 command[2].V. 2006. *iPodMsgPtr. © NXP B.3 iPod communication module 2. October 2006 7 of 24 . }iPodMsg. uint8 para[IPODMSG_PARA_MAX_SIZE]. //uint8 checksum.

// head and tail postion of circular queue static uint8 uart_rx_in. } 2.. length. Only after receiving a complete and valid data packet. parameter and checksum.3. parameter and checksum. All rights reserved. the data packet will be discarded. mode. BRGR1 = (uint16)(Fcclk*1000000/UART_BPS-16) >> 8. After received a byte.h" #define UART_RX_IPODMSG_SIZE (4) // input buffer using circular queue xdata iPodMsg UART_RX_iPodMsg_Buf[UART_RX_IPODMSG_SIZE]. command. // current ceceived byte index static uint8 pos = 0. The “length” is the total byte number of command.3. // baud rate for Baud Rate Generator BRGCON = 0x0. Rev. ES = 1. uart_rx_out. © NXP B. it will be put into a buffer. 2. SSTAT=0xE0. 2006.2 Source code for receiving packet #include ". uart_rx_in = uart_rx_out = 0. 0x55).3. the packet will be stored in the buffer.NXP Semiconductors Audio system with iPod interface Design manual A complete data frame comprises header. The “header” has two bytes (0xff.( (sum of all length/mode/command/parameter bytes) & 0xFF) 2. The “checksum” calculation formula is: 0x100 .3 Receive and send of data packet We send data packet by polling method and receive by interrupt method.3. BRGR0 = (uint16)(Fcclk*1000000/UART_BPS-16) & 0xff. October 2006 8 of 24 . void UART_Recv_ISR(void) interrupt 4 using 0 { byte ch. static bool inSync = false. xdata uint8 * pb_ipodmsg.\include\uart.V. If the byte is invalid.3. 13 — 16. BRGCON = 0x03.1 UART initialization source code void UART_Init(void) { SCON = 0x50.

} if (pos == 1) { if (ch == IPODFRAME_HEADER_1)// the second byte must be 0x55 inSync = true. } } // (pos >= 2) pb_ipodmsg = (uint8 *)&UART_RX_iPodMsg_Buf[uart_rx_in]. pos = 0. // length // invalid packet length if (pos == IPODMSG_LEN_OFFSET && (ch < IPODMSG_MODE_SIZE+IPODMSG_CMD_SIZE © NXP B. All rights reserved. Rev. // if input buffer is full. ch = SBUF. 13 — 16. 2006. October 2006 9 of 24 . } if (!inSync) { if (pos == 0) { if (ch == IPODFRAME_HEADER_0)// the first byte must be 0xff pos++. // test return. discard the byte //if (((uart_rx_in+1) % UART_RX_IPODMSG_SIZE) == uart_rx_out) if (((uart_rx_in+1) & (UART_RX_IPODMSG_SIZE-1)) == uart_rx_out) { //led_red = 1.V. return. return. pb_ipodmsg[pos] = ch.NXP Semiconductors Audio system with iPod interface Design manual RI = 0.

return.3. } pos++. pos = 0. 13 — 16. while(!TI). uart_rx_in = (uart_rx_in+1) & (UART_RX_IPODMSG_SIZE-1).3 Source code for sending packet // send a byte by polling void UART_Send_Byte(byte dat) { ES = 0. Rev. pb_ipodmsg[IPODMSG_LEN_OFFSET]+IPODMSG_LEN_SIZE)) { //uart_rx_in = (uart_rx_in+1) % (UART_RX_IPODMSG_SIZE).3. return. October 2006 10 of 24 . ES = 1. All rights reserved. } led_green = 0. inSync = false. } // last byte is checksum if (pos == IPODMSG_LEN_SIZE+pb_ipodmsg[IPODMSG_LEN_OFFSET]) { if (ch == iPod_Calc_Checksum_Int(pb_ipodmsg. } 2. // discard the packet and resynchronization inSync = false.V.NXP Semiconductors Audio system with iPod interface Design manual || ch > IPODMSG_MODE_SIZE+IPODMSG_CMD_SIZE+IPODMSG_PARA_MAX_SIZE)) { pos = 0. } // send a string by polling © NXP B. TI = 0. 2006. SBUF = dat.

1 Source code // update flag static uint8 update_flag = 0x0. extract useful information and then store in some buffer. for (i=0. The LCD will display the information.i<count.3. October 2006 11 of 24 . 2.3. // iPod status static xdata uint16 song_time_total. #else UART_Send_Byte(bptr[i]). ES = 0. // elapsed time (unit: second) #define SONG_TITLE_LEN 32 // title of current song #define SONG_ARTIST_LEN 24 // singer name of current song static xdata uint8 song_title[SONG_TITLE_LEN+1].NXP Semiconductors Audio system with iPod interface Design manual void UART_Send_Bytes(byte *bptr. // song number of current list static xdata uint8 ipod_status = iPod_STAT_STOPPED.4.i++) { #if 1 // SBUF = bptr[i]. TI = 0. // time of song (unit: second) static xdata uint16 song_time_elapsed. // data need to update static xdata uint16 song_pos = 0. 2006. // title of current song static xdata uint8 song_artist[SONG_ARTIST_LEN+1].V. All rights reserved. while(!TI). 13 — 16.4 Parse a data packet To parse a packet means to analyze the data packet in input buffer. } 2. Rev. #endif } ES = 1. // void iPod_Parse_RecvdMsg() © NXP B. uint8 count) { data uint8 i. // current song position static xdata uint16 song_num = 0.

msgptr->command[1]). switch (mode4cmd) { case MODE4_RES_TIMESTAT: { if (ipod_status != msgptr->para[8]) { ipod_status = msgptr->para[8]. msgptr->para[2]) >> 2. 2006. update_flag |= _BV(BIT_TIMEELAPSED). update_flag |= _BV(BIT_TIMETOTAL). update_flag |= _BV(BIT_STATUS). if (song_time_elapsed != tmp) { song_time_elapsed = tmp. if (song_time_total != tmp) { song_time_total = tmp. // retrieve a packet msgptr = &UART_RX_iPodMsg_Buf[UART_Get_CurIpodMsgPos()]. } tmp = MAKEWORD(msgptr->para[5]. xdata uint16 mode4cmd.NXP Semiconductors Audio system with iPod interface Design manual { xdata iPodMsgPtr msgptr. // if not mode 4. 13 — 16. msgptr->para[6]) >> 2. Rev. October 2006 12 of 24 . } tmp = MAKEWORD(msgptr->para[1]. return. © NXP B. xdata uint16 tmp. } mode4cmd = MAKEWORD(msgptr->command[0]. do not parse it if (msgptr->mode != MODE_AIRMOD) { UART_Remove_iPodMsg().V. All rights reserved.

IPODMSG_MODE_SIZE IPODMSG_CMD_SIZE . } case MODE4_RES_CURPOS: { tmp = MAKEWORD(msgptr->para[2]. &msgptr->para[0]. if ( song_pos != tmp) { song_pos = tmp. 13 — 16.1) && membytecmp(&song_title[1].NXP Semiconductors Audio system with iPod interface Design manual } break. 2006. All rights reserved. if (song_num != tmp) { song_num = tmp. update_flag |= _BV(BIT_SONGPOS). song_title[0]) == 0) { //led_green = 1. msgptr->para[3]). October 2006 13 of 24 . } else © NXP B.V. Rev. } case MODE4_RES_SONGNUM: { tmp = MAKEWORD(msgptr->para[2]. update_flag |= _BV(BIT_SONGNUM). } break. } break. } case MODE4_RES_TITLE: { // do not update if not different from previous song title if ((song_title[0] <= msgptr->length . msgptr->para[3]).

} default: { © NXP B.IPODMSG_MODE_SIZE IPODMSG_CMD_SIZE . } break. October 2006 14 of 24 .NXP Semiconductors Audio system with iPod interface Design manual { //led_green = 0.1. song_title[0]). song_title[0] = msgptr->length . &msgptr->para[0]. membytecpy(&song_artist[1]. song_artist[0]). } break.V. &msgptr->para[0]. if (song_title[0] > SONG_TITLE_LEN) song_title[0] = SONG_TITLE_LEN. &msgptr->para[0]. All rights reserved. song_artist[0]) == 0) { //led_green = 1.1) && membytecmp(&song_artist[1].IPODMSG_MODE_SIZE IPODMSG_CMD_SIZE . if (song_artist[0] > SONG_ARTIST_LEN) song_artist[0] = SONG_ARTIST_LEN.1. update_flag |= _BV(BIT_SONGTITLE). Rev. } else { song_artist[0] = msgptr->length . 13 — 16. membytecpy(&song_title[1]. } case MODE4_RES_ARTIST: { // do not parse if not different from previous song title if ((song_artist[0] <= msgptr->length . update_flag |= _BV(BIT_SONGARTIST).IPODMSG_MODE_SIZE IPODMSG_CMD_SIZE . 2006.

4. Each English character has 16 bytes and Chinese character has 32 bytes. we generate the 8*16 pixel character.V.i++) { b2 |= byte_data & 0x1. 2. } } // remove current packet from input buffer UART_Remove_iPodMsg(). October 2006 15 of 24 .i<7. We also generate some Chinese characters (16*16) for display in LCD. 13 — 16.NXP Semiconductors Audio system with iPod interface Design manual break. Rev.4. Because it’s small and not clear. 2006.4 LCD display module 2. © NXP B. byte_data >>= 1.3 Source code for static byte Reverse_Byte(byte byte_data) { data byte b2 = 0.1 LCD structure and fuction 2. All rights reserved. } 2.2 Character library There is a English character generation libarary (5*7 pixel) in the LCD module. for (i=0. uint8 data i.4.

// init parameter static const byte code SYS_INIT_PARA[8] = { 0x30. M2: 0. W/S: 0. M1: 0. The initialization includes a series of steps to configure parameters. DELAY_CPU_CYCLE(2).i<8.4. M0: 0(internal CG)*/ © NXP B. #else S2P_CLK = HIGH_LEVEL.4 LCD init and display 2.i++) { S2P_DATA = byte_data & 0x1. return b2. All rights reserved. #endif byte_data >>= 1. DELAY_CPU_CYCLE(2). for (i=0. DELAY_CPU_CYCLE(2). byte_data = Reverse_Byte(byte_data).4. /* 0011 0000 B: 1. 13 — 16.V. DELAY_CPU_CYCLE(2). } b2 |= byte_data & 0x1. 2006. } } 2. the LCD should be initialized correctly. October 2006 16 of 24 .1 Init For proper display. S2P_CLK = HIGH_LEVEL. #if RISING_EDGE_VALID S2P_CLK = LOW_LEVEL. Rev. S2P_CLK = LOW_LEVEL.4. } static void S2P_Outp_Byte(byte byte_data) { data uint8 i.NXP Semiconductors Audio system with iPod interface Design manual b2 <<= 1.

//0x28. LCD_Init_Port(). 13 — 16. // 0000 0000 HIBYTE(SAD2_BASE_ADDR). }. i < sizeof(SYS_INIT_PARA)/sizeof(*SYS_INIT_PARA).4. // only use SAD1 and SAD2 area static const byte code SCROLL_PARA[10] = { LOBYTE(SAD1_BASE_ADDR). // sed1335 init instruction LCD_Write_Command(SYSTEM_SET). SCREEN_HEIGHT.V. //0x00 }. October 2006 17 of 24 .NXP Semiconductors Audio system with iPod interface Design manual /* 1000 0111 /* 0000 0111 /* 0010 0111 /* 0100 0010 /* WF: 1. C/R: 39 TC/R: 66 SED1335 OSC:10MHz lpc936 internal OSC 7.4. //0x42. /* APH: 0 */ SCREEN_HEIGHT. 2. Rev. HIBYTE(SAD3_BASE_ADDR). 0x07. // 0000 0000 // 0000 0000 // 1111 0000 SAD2L: 0x00 SAD1H: 0x00 SL1: 240 LOBYTE(SAD2_BASE_ADDR). // Scroll settings © NXP B. LOBYTE(SAD4_BASE_ADDR). AP>=C/R) */ HIBYTE(AP). 0x27. // 0xf0. i++) { LCD_Write_Data(SYS_INIT_PARA[i]). FX: 7(width = FX+1 pixel) */ FY: 7 (height=FY+1 pixel) */ */ (byte number of each line 0x27+1=40) */ 0x87. LOBYTE(AP). 2006. // 0001 0000 // 1111 0000 SAD2L: 0x00 SAD2H: 0x10 SL2: 240 // 0000 0000 SAD3L: 0x00 // not use SAD3 // 0000 0000 SAD4L: 0x00 // not use SAD4 // System config for (i = 0. } LCD_Write_Command(SCROLL). SCREEN_HEIGHT. HIBYTE(SAD4_BASE_ADDR). 0x30. of a frame) */ /* APL: 40 (memory size of each line: 40 bytes. All rights reserved. in lines. LOBYTE(SAD3_BASE_ADDR).2 Source code for initialization // init LCD display parameter and interface void LCD_Init(void) { uint8 i. HIBYTE(SAD1_BASE_ADDR).3728MHz*/ /* L/F: 240(the height.

j. LCD_Clear_AllMemory(). uint16 pixel_col. // 0001 0110 LCD_Write_Command(CSR_RIGHT). const byte* pByte) { data uint16 i.4. All rights reserved. LCD_Set_RAMCursorAddr(0x00). LCD_Write_Data(0x0c). Rev. LCD_Write_Command(OVLAY). byte* pWork. LCD_Set_CursorDirection(CSRDIR_DOWN). uint16 pixel_height. i < sizeof(SCROLL_PARA)/sizeof(*SCROLL_PARA). //LCD_Write_Data(0x1f). uint16 pixel_row. LCD_Write_Command(DISP_OFF). 2006.3 Source code for display character bool LCD_Disp_GraphDotCode( uint8 sad_num. 13 — 16.4. } 2. LCD_Write_Data(0x07). // 1000 1111 CM: 1. CRY: 15 LCD_Write_Command(DISP_ON). LCD_Write_Data(0x1f).NXP Semiconductors Audio system with iPod interface Design manual for (i = 0. LCD_Write_Data(0x8f). i++) { LCD_Write_Data(SCROLL_PARA[i]).V. LCD_Write_Data(0x00). uint16 pixel_width. October 2006 18 of 24 . LCD_Write_Command(CSRFORM). } LCD_Write_Command(HDOT_SCR). © NXP B.

j += 8) // { //pWork = pByte + j/8. col + j)) // return false. pixel_col + j)) { // LED_DISP(1. j < pixel_width. 13 — 16. //pWork += pixel_width/8. October 2006 19 of 24 .1. Rev. uint16 pixel_row. // pWork = pByte + (j>>3). pixel_row. // if (!LCD_Set_SADCursorPos(sad_num. pWork += (pixel_width>>3). return false. LCD_Write_Command(MWRITE). } bool LCD_Disp_GraphChar(uint8 sad_num. for (i = 0. 2006. byte ch) { © NXP B.NXP Semiconductors Audio system with iPod interface Design manual // x axes for (j = 0. All rights reserved. i++) { LCD_Write_Data(*pWork). row + i. uint16 pixel_col. i < pixel_height. } } } return true.V. } if (pixel_col + j < SCREEN_WIDTH) { // y axes //if (!LCD_Set_GraphCursorPos(sad_num.0).

pixel_col += CHAR_WIDTH. } return true. } if (pixel_row >= SCREEN_HEIGHT) return false. All rights reserved. Rev. const byte *pch.NXP Semiconductors Audio system with iPod interface Design manual if (ch < ' ' || ch > 'z') { ch = 0x20.index++) { if (!LCD_Disp_GraphChar(sad_num. CHAR_WIDTH. } 3. pixel_col. /*uint8 disp_dir. pixel_row. CHAR_HEIGHT. } return (LCD_Disp_GraphDotCode(sad_num. pch[index])) return false. ASCII_0816[ch-ASCII_MIN])). if (pixel_col >= SCREEN_WIDTH) { pixel_row += CHAR_HEIGHT. pixel_row. } bool LCD_Disp_GraphStringNum(uint8 sad_num.1 Schematic © NXP B. pixel_col. uint8 size) { uint8 index. 2006. October 2006 20 of 24 . uint16 pixel_col. Appendix 3.index<size. for (index=0. 13 — 16.*/ uint16 pixel_row. pixel_col = 0.V.

.

October 2006 22 of 24 .2 BOM list © NXP B.NXP Semiconductors Audio system with iPod interface Design manual 3. 2006. Rev.V. 13 — 16. All rights reserved.

service names and trademarks are property of their respective owners. expressed or implied. All rights reserved. at any time and without notice.V.2 Disclaimers General — Information in this document is believed to be accurate and reliable. space or life support equipment. Suitability for use — NXP Semiconductors products are not designed. NXP Semiconductors does not give any representations or warranties as to the accuracy or completeness of information included herein and shall have no liability for the consequences of use of such information. as to the accuracy or completeness of such information and shall have no liability for the consequences of use of such information.5 Trademarks Notice: All referenced brands. NXP Semiconductors accepts no liability for inclusion and/or use of NXP Semiconductors products in such equipment or applications and therefore such inclusion and/or use is for the customer’s own risk. <Patent ID> — owned by <Company name> 4. However.1 Definitions Draft — The document is a draft version only. © NXP B. nor in applications where failure or malfunction of a NXP Semiconductors product can reasonably be expected to result in personal injury. NXP Semiconductors makes no representation or warranty that such applications will be suitable for the specified use without further testing or modification. including without limitation specifications and product descriptions. Rev. 4. NXP Semiconductors does not give any representations or warranties. October 2006 23 of 24 . which may result in modifications or additions. authorized or warranted to be suitable for use in medical. <Name> — is a trademark of NXP B. This document supersedes and replaces all information supplied prior to the publication hereof. The content is still under internal review and subject to formal approval.3 Licenses Purchase of NXP <xxx> components <License statement text> 4. Right to make changes — NXP Semiconductors reserves the right to make changes to information published in this document. death or severe property or environmental damage. Applications — Applications that are described herein for any of these products are for illustrative purposes only. product names. military. 4.V.NXP Semiconductors Audio system with iPod interface Design manual 4. 2006. aircraft.4 Patents Notice is herewith given that the subject device uses one or more of the following patents and that each of these patents may have corresponding patents in other jurisdictions. 13 — 16. Legal information 4.

2006<(D)D Month YYYY> Document identifier: <DOC_ID> ...........................3.........4..........3..............................4................................3..............2 2..........1 2..................com Date of release: Oct.................................................4 2.......2 2..........2 2...........................3 2.................4.......1 3.4.......... please visit: http://www...3 2.............. 2006.........................................2 4.................2.......................15 Source code for......................................................................8 UART initialization source code ....7 framework ......4... 16..........5 5.........4..... For more information.....nxp..................4.........22 Legal information .11 LCD display module .... email to: sales................3 2...15 Character library.....3 2....V...........................3..... 4.3.........1 2. All rights reserved.........23 Definitions .....2.........................................4 Scan method ...............................23 Trademarks .......4...........................................com For sales office addresses......18 Appendix .......................1 4.............................nxp.........1 2.................................................23 Contents.........4 Software flowchart.....................addresses@www..........4 Source code ...........24 Please be aware that important notices concerning this document and the product(s) described herein....1 2........................ have been included in the section 'Legal information'.........20 schematic ................2 2............1 2.......................3.............17 Source code for display character. © NXP B...................................2 4...15 LCD init and display ........3........................7 Receive and send of data packet .......................8 Source code for sending packet..............3.............5 iPod communication module ..3.....4 2................................. Contents 1................................. 2.................4.......3 Software framework ...4........3 3..........................3 4.........................2 2...2 2............................10 Parse a data packet ..................16 Source code for initialization .........4 Keyboard scan module ............4 4....4 2......3.....................1 2.....................4....... Introduction of system software ...........2 2...3......23 Licenses .......23 Disclaimers........ 3..................NXP Semiconductors Audio system with iPod interface Design manual 5................3 Introduction ..11 Source code ........................1 1..........15 LCD structure and fuction..............20 BOM list.16 Init ................................23 Patents ........ 1.....7 iPod message data structure....................1 2.....3 Software design and implementation ..........8 Source code for receiving packet ....