[c]代码库
#include ****
//sbit
sbit DataBus = P1;
sbit ready = P0^3;
sbit succeed = P0^5;
typedef unsigned char uchar;
typedef unsigned int uint;
//var
bit flag;
uchar recievedArray [10];
uchar sendingArray []={0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0};
//declare
void paradel_init();
uint sentChar(uchar dat);
bit readyOn();
uchar recieveChar();
bit checkHas();
bit sentArray (uchar array[]);
//main
int main(){
paradel_init();
flag = readyOn();
while(flag){
while(recieveChar() != '\0');
if(checkHas){
sentArray (sendingArray);
}
}
return 0;
}
//functions
void paradel_init(){
ready = 0;
succeed = 0;
}
uint sentChar(uchar dat){
if(ready = 1){
DataBus = dat;
while (!succeed);
ready = 0;
return 1;
}
return 0;
}
bit readyOn(){
return 1;
}
uchar recieveChar(){
uchar content;
if(ready){
content = DataBus;
while(ready)
succeed = 1;
}
succeed = 0;
return content;
}
bit sentArray (uchar array[]){
uint s;
uint count = 0;
for( s = 0; s<sizeof(array); array++){
count += sentChar(array[s]);
if(count == sizeof(array)-1) return 1;
}
return 0;
}
bit checkHas(){
if(sendingArray[0]!='\0'){
return 1;
}
return 0;
}
by: 发表于:2017-08-08 11:15:26 顶(0) | 踩(0) 回复
??
回复评论