User-defined Download Application Note User-defined Download Application Note 1. Applied Products: SM59XX Series, SM59DXX Series, SM59RXX Series. 2. Object: User can define command as entry ISP password through ISAP software to run programming. 3. Operation (For example SM59D04G2) 3.1 ISAP Operating Step 3.1.1 Program main code and ISP service code into the IC. 3.1.2 Power on your target board and connect to your PC. 3.1.3 Click ISAP icon to activate ISAP V2.X. 3.1.4 Select “User-defined” and set baud rate speed according to customer’s transmission speed. For example, we select 115200bps due to the sample code using 115200bps. 3.1.5 Load sample code into ISAP. 3.1.6 Key in your user-defined command into ISAP according to your receive command of UART interrupt subroutine. User-defined command length range is between 1~32 byte, and data type is hexadecimal. Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 1 Ver. A 2009/08 User-defined Download Application Note 3.1.7 Press “Autorun” then ISAP will start programming. When finish programming, ISAP shows “MCU Reset Succeeded!”. Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 2 Ver. A 2009/08 User-defined Download Application Note 3.2 Flow Chart PC MCU ISAP V2.X.X Initial UART Run customer's main code NO Send user-defined command Receive data YES Enter UART interrupt NO Check data = userdefined data YES NO Check data number = nCommandLength YES NO Receive ACK Send 0x5A YES Fail Start ISP erase, program, protect, reset LJMP ISP address Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 3 Ver. A 2009/08 User-defined Download Application Note 3.3 Sample code 3.3.1 Keil C Description main.c (Main program) //This sample code included main.c、GoToISP_Low.A51 #include "SM59D04G2.h" #define nCommandLength 32 #define nAckCommand 0x5A unsigned char UartCmdCount; unsigned char code CommandArray[nCommandLength]= {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32}; extern GoToISP_Low(); void delayms(unsigned int mscnt) { unsigned int i; while(mscnt--) { for(i=0;i<250;i++); } } void init_UART_timer1(unsigned char BR) { SCON = 0x50; //SCON: serail mode 1, 8-bit UART, enable receive TMOD = 0x22; //TMOD: timer 1, mode 2, 8-bit reload PCON = 0x80; //SMOD = 1; TH1 = BR; //Baud:57600 fosc=22.1184MHz TR1 = 1 ; //timer 1 run EA = 1; //all interrupt enable ES = 1; //UART enable } void init_UART_timer2(unsigned int T2value) { RCAP2L = (char)T2value; RCAP2H = (char)(T2value>>8); T2CON = 0x34; SCON = 0x50; EA = 1; //all interrupt enable ES = 1; //UART enable } void main(void) { init_UART_timer2(0xFFFA);//choise Timer 1 or Timer 2 as baud rate generator //init_UART_timer1(0xFF); //SyncMOS_GoToISP via UART //TH1 = 0xFF; //12T, 3.579MHz(19200), 11.0592MHz(57600) // 6T, 3.579MHz(38400), 11.0592MHz(115200) Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 4 Ver. A 2009/08 User-defined Download Application Note //TH1 = 0xFE; //TH1 = 0xFD; //TH1 = 0xFC; //TH1 = 0xFB; //TH1 = 0xF7; //TH1 = 0xF5; //TH1 = 0xF3; // // while(1) { P0 = 0xF0; P0 = 0x0F; P2 = 0xF0; P2 = 0x0F; } //12T, 14.31818MHz(38400), 22.1184MHz(57600), 14.7456MHz(38400) // 6T, 22.1184MHz(115200) //12T, 4MHz(7200), 8MHz(14400), 8.192MHz(14400), 16MHz(28800) // 6T, 4MHz(14400),8MHz(28800), 8.192MHz(28800), 16MHz(57600) // // 6T, 14.31818MHz(38400), 14.7456MHz(38400) //12T, 18.432MHz(19200) // 6T, 18.432MHz(38400) //12T, 24.576MHz(14400), 25MHz(14400) // 6T, 24.576MHz(28800), 25MHz(28800) //12T, 20MHz(9600) // 6T, 20MHz(19200) //12T, 6MHz(2400), 12MHz(4800), 24MHz(9600) // 6T, 6MHz(4800), 12MHz(9600), 24MHz(19200) delayms(300); delayms(300); delayms(300); delayms(300); } GoToISP_Low. A51 void serial(void) interrupt 4 { if(RI) { if(SBUF == CommandArray[UartCmdCount]) UartCmdCount++; else UartCmdCount=0; RI = 0 ; if(UartCmdCount==nCommandLength) { IE = 0x00; //disabling interrupt SBUF = nAckCommand; while(!TI); TI = 0; T2CON = 0x00; //disabling T2 because using T1 baud rate generator in ISP code GoToISP_Low(); //LJMP 3E00H ISP code address } } else TI=0; } ; GoToISP_Low.A51 NAME GoToISP_Low ?PR?GoToISP_Low?GOTOISP_LOW SEGMENT CODE PUBLIC GoToISP_Low RSEG ?PR?GoToISP_Low?GOTOISP_LOW USING 0 GoToISP_Low: MOV DPTR,#3E00H ;LJMP 3E00H ISP code address Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 5 Ver. A 2009/08 User-defined Download Application Note PUSH DPL PUSH DPH RETI END 3.3.2 Assembly Description Main program nCommandLength EQU 32 ;setting command length by user UARTCmdCount EQU 20H T2CON EQU 0C8H RCAP2L EQU 0CAH RCAP2H EQU 0CBH ORG 0000H AJMP ISP_Entry ORG 0023H AJMP UART_INTERRUPT ISP_Entry: ACALL SyncMOS_GoToISP ;initial setting ;;; ;;; main code start ;;; /* LED display demo */ MOV DPTR,#TABLE_01 ;DPTR point to data area START: MOV R0,#0 ; MOV R1,#8 ;8 datas LOOP: MOV A,R0 ;put R0 contect to A MOVC A,@A+DPTR ;use indirect address get data, and put into A MOV P0,A ;put ACC to Port 0 MOV P1,A ;put ACC to Port 1 ACALL DELAY100MS ;delay 0.1 second INC R0 ;R0 point to next data DJNZ R1,LOOP ;if R1 != 0 then jump to LOOP SJMP START ;if R1=0 then jump to START ;;; dealy subroutine DELAY100MS: MOV R5,#10 ;Dealy 10x10ms=100ms DELAY10MS: MOV R6,#50 ;delay time 10ms @ 11.0592MHz DELAY01: MOV R7,#99 DJNZ R7,$ ; Inner loop delay DJNZ R6,DELAY01 ; DJNZ R5,DELAY10MS RET ;;; TABLE_01: DB 11100111B DB 11000011B DB 10000001B DB 00000000B Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 6 Ver. A 2009/08 User-defined Download Application Note DB DB DB DB 10000001B 11000011B 11100111B 11111111B ;;; ;;; main code End ;;; ;;; ;;; SyncMOS_GoToISP Subroutine ;;; SyncMOS_GoToISP: ;;;======UART Timer1 setting============= ;MOV TMOD,#00100001B ;Timer 1 is mode1 is mode 2, Timer 0 is mode 1 ;;; ;MOV TH1,#0FFH ;baud rate, 12T, 3.579MHz(19200), 11.0592MHz(57600) ; 6T, 3.579MHz(38400), 11.0592MHz(115200) ;MOV TH1,#0FEH ;baud rate, 12T, 14.31818MHz(38400), 22.1184MHz(57600), 14.7456MHz(38400) ; 6T, 22.1184MHz(115200) ;MOV TH1,#0FDH ;baud rate, 12T, 4MHz(7200), 8MHz(14400), 8.192MHz(14400), 16MHz(28800) ; 6T, 4MHz(14400),8MHz(28800), 8.192MHz(28800), 16MHz(57600) ;MOV TH1,#0FCH ;baud rate, ; 6T, 14.31818MHz(38400), 14.7456MHz(38400) ;MOV TH1,#0FBH ;baud rate, 12T, 18.432MHz(19200) ; 6T, 18.432MHz(38400) ;MOV TH1,#0F7H ;baud rate, 12T, 24.576MHz(14400), 25MHz(14400) ; 6T, 24.576MHz(28800), 25MHz(28800) ;MOV TH1,#0F5H ;baud rate, 12T, 20MHz(9600) ; 6T, 20MHz(19200) ;MOV TH1,#0F3H ;baud rate, 12T, 6MHz(2400), 12MHz(4800), 24MHz(9600) ; 6T, 6MHz(4800), 12MHz(9600), 24MHz(19200) ;SETB TR1 ;enable Timer 1 ;MOV PCON,#10000000B ;set SMOD = 1 ;;;====================================== ;;; ;;;======UART Timer2 setting============= ;choise Timer 1 or Timer 2 as baud rate generator MOV RCAP2H,#0FFH MOV RCAP2L,#0FAH MOV T2CON,#34H ;;;====================================== MOV SCON,#01010000B ;serial mode 1, REN=1, TI=0, RI=0 MOV IE,#90H ;enable UART interrupt MOV UARTCmdCount,#00H RET UART_INTERRUPT: JB RI,RX ; if RI=1 jump RX,else clear TI CLR TI RETI RX: CLR RI PUSH ACC Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 7 Ver. A 2009/08 User-defined Download Application Note PUSH DPL PUSH DPH MOV A,UARTCmdCount MOV DPTR,#COMMAND_TABLE MOVC A,@A+DPTR CJNE A,SBUF,CLR_UARTCmdCount INC UARTCmdCount MOV A,UARTCmdCount CJNE A,#nCommandLength,RETURN CLR EA MOV SBUF,#5AH ;transmit ack MOV DPTR,#3E00H ;LJMP 3E00H ISP code address PUSH DPL PUSH DPH JNB TI,$ CLR TI MOV T2CON,#00H ;disabling T2 because using T1 baud rate generator in ISP code RETI CLR_UARTCmdCount: MOV UARTCmdCount,#00H RETURN: POP DPH POP DPL POP ACC RETI COMMAND_TABLE: DB 01H,02H,03H,04H,05H,06H,07H,08H ;to define command by user DB 09H,10H,11H,12H,13H,14H,15H,16H DB 17H,18H,19H,20H,21H,22H,23H,24H DB 25H,26H,27H,28H,29H,30H,31H,32H END Note: ※ The sample codes attach in ISAP V2.X.X setup directory “C:\Program Files\SyncMOS\ SyncMOS Writers\ISAP\OnlineUpdate\User-defined”. ※ SM59XX Series and SM59DXX Series using Timer1 as baud rate generator in ISP service code. If using Timer2 as baud rate generator, please writing T2CON = 0x00 before jumping ISP to avoid occupying UART port. Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 8 Ver. A 2009/08 User-defined Download Application Note 4. Baud Rate Reference Table 4.1 Timer 1,TH1[7:0] Setting Reference Table 4.1.1 Listing the part of frequencies as shown below. Please download calculation program on SyncMOS website if you need other frequency. (http://www.syncmos.com.tw/download_file/UART.rar) 4.1.2 No value of the cell means deviation too much, so we don’t suggest user to use it. Baud rate (BPS) 11.0592MHz/12T 115200 57600 22.1184MHz/12T 11.0592MHz/6T 28.6MHz/12T 28.63636MHz/12T 14.31818MHz/6T 36.81875MHz/12T 36.864MHz/12T 18.432MHz/6T FC FB F8 F6 FF FF 38400 FE FD 28800 FE FC 19200 FD FA 14400 FC F8 F3 9600 FA F4 EC 7200 F8 F0 EB E5 4800 F4 E8 E1 D8 2400 E8 D0 C2 B0 1200 D0 A0 84 60 Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 9 Ver. A 2009/08 User-defined Download Application Note 4.2 Timer 2,RCAP2[15:0] Setting Reference Table 4.2.1 Listing the part of frequencies as shown below. Please download calculation program on SyncMOS website if you need other frequency. (http://www.syncmos.com.tw/download_file/UART.rar) 4.2.2 No value of the cell means deviation too much, so we don’t suggest user to use it. Baud rate (BPS) 3.579MHz/6T 14.7456MHz/12T 115200 FFFE FFFC 57600 FFFC FFF8 FFF5 FFEF FFEC 38400 FFFA FFF4 FFF0 FFE6 FFE2 28800 FFF8 FFF0 FFEA FFDD FFD8 19200 FFF4 FFE8 FFDF FFCC FFC4 14400 FFF1 FFE0 FFD5 FFBB FFB0 9600 FFE9 FFD0 FFBF FF98 FF88 7200 FFE1 FFC0 FFA9 FF75 FF60 4800 FFD1 FFA0 FF7E FF30 FF10 2400 FFA3 FF40 FEFC FE5F FE20 1200 FF46 FE80 FDF7 FCBF FC40 20MHz/12T 32MHz/12T 16MHz/6T 36.864MHz/12T 18.432MHz/6T FFF6 Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0140 10 Ver. A 2009/08