Easy-Downloader V1.1 with SDCC

[05-23 02:47:29]   来源:http://www.88dzw.com  单片机电路图   阅读:8924

文章摘要: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,

Easy-Downloader V1.1 with SDCC,标签:电路图讲解,电路图练习,http://www.88dzw.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>

上一页  [1] [2] [3] [4]  下一页


Tag:单片机电路图电路图讲解,电路图练习电子电路图 - 单片机电路图

《Easy-Downloader V1.1 with SDCC》相关文章