Easy-Downloader V1.1 with SDCC
[09-08 11:37:34] 来源:http://www.88dzw.com 微机|单片机 阅读:8650次
文章摘要: } The pointer s points to the start address of string. It will send character to serial port with function putchar while the character is not the terminator byte!Sdcc has no putchar( ) function, so we must build it before we can use. I wrote a simple putchar( ) as my assembly
Easy-Downloader V1.1 with SDCC,标签:电路设计,http://www.88dzw.com}
The pointer s points to the start address of string. It will send character to serial port with function putchar while the character is not the terminator byte!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.
Tag:微机|单片机,电路设计,家电维修 - 单元电路介绍 - 微机|单片机
- 上一篇:PIC单片机控制的小鸭牌药膳煲
《Easy-Downloader V1.1 with SDCC》相关文章
- › Easy 51Pro单片机编程器的制作与使用
- › Easy-Downloader V1.1 with SDCC
- › EasyRecovery应用详解
- › 提示"This MotherBoard does not support Easy Energy
- 在百度中搜索相关文章:Easy-Downloader V1.1 with SDCC
- 在谷歌中搜索相关文章:Easy-Downloader V1.1 with SDCC
- 在soso中搜索相关文章:Easy-Downloader V1.1 with SDCC
- 在搜狗中搜索相关文章:Easy-Downloader V1.1 with SDCC