电子文章 | 电子资料下载 | 家电维修 | 维修资料下载 | 加入收藏 | 全站地图
您现在所在位置:电子爱好者电子文章电子电路图单片机电路图Easy-Downloader V1.1 with SDCC

Easy-Downloader V1.1 with SDCC

03-13 01:54:52 | http://www.5idzw.com | 单片机电路图 | 人气:924
标签:电路图讲解,电路图练习,http://www.5idzw.com Easy-Downloader V1.1 with SDCC,http://www.5idzw.com
Sdcc has no putchar( ) function, so we must build it before we can use. I wrote a simple putchar( ) as my assembly code.
 
void putchar(char c)
{
 while(!TI); 
 TI=0;
 SBUF = c;
}

We test TI bit before we can write a byte to SBUF. While TI is not set (buffer is not free) keep polling it, when it set, clear it and write a byte to SUF.

The same as putchar( ) function, I had built the getchar( ) for this board to make it compatible with old version.
 

char getchar(void)
{
 char c;
 while(!RI);
 RI =0;
 c = SBUF;
 putchar(c);    // echo to terminal
 return SBUF;
}

Now the code polls the RI bit, when it set, clear it and read SBUF and simply echo the received character with putchar( ) function.

The important function is getnum ( ) function. Let me explain how it works?
 

unsigned int getnum()
{
    char s[6]; 
    char c;
    char i;
    unsigned int temp16; 
 c = 0;
 i=0;
  for (i = 0; c != 0xa; i++) // loop until CR has entered
    { 
        putchar(xon); // send xon to signal host to send byte
        c = getchar(); // get character from serial port
  if(c == 0xd) c=0xa; // convert CR to LF to make it compatible with ez31 and ez41
        s[i] = c; // save character to array
    }
    s[i-1] = 0; // put terminator at the end of string

// convert ascii to integer (atoi(s))
  temp16 = 0;
 for(i=0; s[i] != 0; i++) temp16 = 10*temp16 + s[i]-'0';
    return temp16; // return 16-bit for number of byte counting
}

Look at the red one, it is a simple for loop with condition to check the received character is NEWLINE or not. If not it will save the character being received to array s[i]. The putchar(xon) sends the xon to host to let it know the board is ready to receive a byte. The getchar( ) is not echo the received byte. However it converts CF to LF. When the loop found LF or 0xa, it will exit from the for loop and save terminator byte to s[i-1].

The ascii 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 for programming the hex file into a 20-pin microcontrollers, 89C2051/4051. Since the hex file produced by sdcc is not sorted from low address to high address. The old version, EZ31 has bug for such hex file. So I recommened to use EZ4.1 for program loading.



 


  • schematic:  
  • Layout in pdf:    
  • c compiler for 8051:   
  • firmware:  
  • HEX file:    
  • EZDL4:  
  • orcad files (schematic, layout):    
  • gerber file:    

  • 资料下载.rar

    Errata

    • 18 March 2004: found hardware schematic error at MAX232. The error is that pin 2 on the D-SUB 9 connector must be connected to pin 13 on the MAX232, not pin 8. The error had reported by Henrik Olesen, student at the University of Southern Denmark.

      Below picture shows how to modify the pcb!

    上一页  [1] [2] 

    ,Easy-Downloader V1.1 with SDCC
    关于《Easy-Downloader V1.1 with SDCC》的更多文章