complete schematic, cad pcb layout of easy-downloader v1.1 modified firmware with sdcc. i am very happy to use sdcc f writing firmware of my project. the compiled code is very compact nice. after i succeeded writing a new firmware of xtimer easy-downloader v1.1 with sdcc. i cannot stop preparing a new page that gives the idea how to use sdcc of course it's time to renovate my old project with cad. f now i can design the hardware, draw a schematic, write the firmware layout the pcb. so i think why shouldn't begin with easy-downloader. since the programmer board will enable learning developing the small project with a cheap 20-pin mcu easily. figure 1: complete hardware schematic of easy-downloader v1.1 ( see errata below). easy1_3.pdfhardware the hardware has a bit change at rs232 level converter. now the circuit uses a popular rs232 level converter, max232. also i cut the bridge diode at the dc input, now i use only one diode to prevent wrong polarity of a given dc adapter. layout the pcb layout was made with cad layout plus. the gerber file is available at download section below. here i like to show how nice it is. the top bottom layers are shown in figure 2 figure 3. figure 4 shows the component placement layout. figure 2: top layer pcb x2 size. figure 3: bottom layer pcb x2 size. figure 4: component placment layout.bill of materials the component list is shown in figure 5. u1 the master chip must be programmed with writer1.hex befe the programmer board can run properly. q2 q3 are to92 plastic package! with a can package, pin positions may differ on the layout. you can use any small signal transists to replace them. vb1 is male type! all resists can be 1/4w 1/8w 5%. bill of materials january 4,2004 10:44:35 page1 item quantity reference part ______________________________________________ 1 2 c1,c2 30pf disceramic 2 2 c8,c3 10uf 16v electrolytic 3 1 c4 10uf 10v electrolytic 4 5 c5,c6,c7,c12,c13 10uf electrolytic 5 1 c9 470uf 25v electrolytic 6 2 c10,c11 0.1uf multilayer 7 2 c14,c15 0.1uf multilayer 8 1 d1 power small red led f power indicat 9 1 d2 1n4007 silicon rectifier diode 10 1 j1 dc jack 11 1 q1 11.0592mhz low profile crystal 12 1 q2 2n2907 pnp small signal transist 13 1 q3 2n2222a npn small signal transist 14 5 r1,r3,r6,r10,r11 10k 15 1 r2 250 16 1 r4 1150 17 1 r5 2150 18 1 r7 4.7k 19 1 r8 1k 20 1 r9 2k 21 1 u1 at89c2051 20-pin dip microcontroller with 2kb flash 22 1 u2 74ls373 d-type ff 23 1 u3 20-pin zif (zero-ion-fce) socket 24 1 u4 lm317/to adjustable regulat 25 1 u5 max232a 16-pin dip rs232 level converter 26 1 u6 lm7805/to fix +5v voltage regulat 27 1 vb1 sub-d 9 (male) f null cable db9 connectfigure 5: component list.software sdcc has the header file that declares bit variables we can use them in program directly. we can define the specified bits as below, #define lm317 p3_5 #define le p3_7 #define prog p3_2 #define rdy p3_3 #define xtal p3_4 #define p10 p1_0 #define p11 p1_1 #define p12 p1_2 #define p13 p1_3 #define p14 p1_4in c program, we can use assignment statement to set clear them directly. f instance, function that makes low to high transition at p3.2, pulseprog() { prog = 0; prog = 0; prog = 0; prog = 1; }the ii strings were defined with modifier, 'code', so the compiled code will place them in code memy space. code title[] = '\n\r easy-downloader v1.3 f atmel 89c2051/4051 (sdcc version)'; code prompt[] = '\n\r >'; code ok[] = '\n\r ok'; i have built function that print string to terminal, to make it compatible with the old version with micro-c. look at the source cod here, putstr( *s) { i=0; c; while((c=*(s+(i++)))!= 0) put(c); // while byte is not terminat, keep sending }the pointer s points to the start address of string. it will send acter to serial pt with function put while the acter is not the terminat byte! sdcc has no put( ) function, so we must build it befe we can use. i wrote a simple put( ) as my assembly code. void put( c) { while(!ti); ti=0; sbuf = c; }we test ti bit befe we can write a byte to sbuf. while ti is not set (buffer is not free) keep polling it, when it set, clear it write a byte to suf. the same as put( ) function, i had built the get( ) f this board to make it compatible with old version. get(void) { c; while(!ri); ri =0; c = sbuf; put(c); // echo to terminal return sbuf; }now the code polls the ri bit, when it set, clear it read sbuf simply echo the received acter with put( ) function. the imptant function is getnum ( ) function. let me explain how it wks? unsigned int getnum() { s[6]; c; i; unsigned int temp16; c = 0; i=0; f (i = 0; c != 0xa; i++) // loop until cr has entered { put(xon); // send xon to signal host to send byte c = get(); // get acter from serial pt if(c == 0xd) c=0xa; // convert cr to lf to make it compatible with ez31 ez41 s[i] = c; // save acter to array } s[i-1] = 0; // put terminat at the end of string // convert ii to integer (atoi(s)) temp16 = 0; f(i=0; s[i] != 0; i++) temp16 = 10*temp16 + s[i]-'0'; return temp16; // return 16-bit f number of byte counting }look at the red one, it is a simple f loop with condition to check the received acter is newline not. if not it will save the acter being received to array s[i]. the put(xon) sends the xon to host to let it know the board is ready to receive a byte. the get( ) is not echo the received byte. however it converts cf to lf. when the loop found lf 0xa, it will exit from the f loop save terminat byte to s[i-1]. the ii string that saved in array s[] will be converted to 16-bit number with atoi code. most of the high level code are the same as previous version with micro-c. you may study them in the source code then. let me shows you how to use sdcc to compile the source code again. the sample below uses batch file, s.bat. c:\sdcc\app>s c:\sdcc\app>path=c:\sdcc\bin c:\sdcc\app>sdcc writer1.c library file /sdcc/share/sdcc/lib/small/libsdcc.lib library file /sdcc/share/sdcc/lib/small/libint.lib library file /sdcc/share/sdcc/lib/small/liblong.lib library file /sdcc/share/sdcc/lib/small/libfloat.lib c:\sdcc\app>packihx writer1.ihx>writer1.hex packihx: read 166 lines, wrote 75: ok. c:\sdcc\app>the batch file s.bat contains, path=c:\sdcc\bin sdcc writer1.c packihx writer1.ihx>writer1.hex the output machine code is hex file with *.ihx extension. we can use a tool, packihx to convert such hex file with *.ihx to *.hex easily. the ez4.1 is suitable f programming the hex file into a 20-pin microcontrollers, 89c2051/4051. since the hex file produced by sdcc is not sted from low address to high address. the old version, ez31 has bug f such hex file. so i recommened to use ez4.1 f program loading. schematic: layout in pdf: c compiler f 8051: firmware: hex file: ezdl4: cad files (schematic, layout): gerber file: 資料下載.rarerrata 18 march 2004: found hardware schematic err at max232. the err is that pin 2 on the d-sub 9 connect must be connected to pin 13 on the max232, not pin 8. the err had repted by henrik olesen, student at the university of southern denmark. below picture shows how to modify the pcb!