00001
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "asuro.h"
00038
00039
00040
00041
00068 void SerWrite (
00069 unsigned char *data,
00070 unsigned char length)
00071 {
00072 unsigned char i = 0;
00073
00074 UCSRB = 0x08;
00075 while (length > 0)
00076 {
00077 if (UCSRA & 0x20)
00078 {
00079 UDR = data[i++];
00080 length --;
00081 }
00082 }
00083 while (!(UCSRA & 0x40))
00084 ;
00085
00086 for (i = 0; i < 0xFE; i++)
00087 for (length = 0; length < 0xFE; length++);
00088 }
00089
00090
00091
00092
00135 void SerRead (
00136 unsigned char *data,
00137 unsigned char length,
00138 unsigned int timeout)
00139 {
00140 unsigned char i = 0;
00141 unsigned int time = 0;
00142
00143 UCSRB = 0x10;
00144
00145 if (timeout != 0)
00146 {
00147
00148
00149
00150
00151 while (i < length && time++ < timeout)
00152 {
00153 if (UCSRA & 0x80)
00154 {
00155 data [i++] = UDR;
00156 time = 0;
00157 }
00158 }
00159 if (time > timeout)
00160 data [0] = 'T';
00161 }
00162 else
00163 {
00164
00165
00166
00167
00168 while (i < length)
00169 {
00170 if (UCSRA & 0x80)
00171 data [i++] = UDR;
00172 }
00173 }
00174 }