00001 #include <ez8.h> 00002 #include "main.h" 00003 #include "driver.h" 00004 00013 void adbusoutput(char c){ 00014 ADBUSOUT = c; 00015 } 00016 00024 void adress_enable_on(){ 00025 char bus = CONTROLBUSIN; 00026 CONTROLBUSOUT = bus | 0x01; 00027 } 00028 00036 void adress_enable_off(){ 00037 char bus = CONTROLBUSIN; 00038 CONTROLBUSOUT = bus & 0xFE; 00039 } 00040 00048 void adress_decode_on(){ 00049 char bus = CONTROLBUSIN; 00050 CONTROLBUSOUT = bus | 0x02; 00051 } 00052 00060 void adress_decode_off(){ 00061 char bus = CONTROLBUSIN; 00062 CONTROLBUSOUT = bus & 0xFD; 00063 } 00064 00072 void output_function_enable_on(){ 00073 char bus = CONTROLBUSIN; 00074 CONTROLBUSOUT = bus | 0x04; 00075 } 00076 00084 void output_function_enable_off(){ 00085 char bus = CONTROLBUSIN; 00086 CONTROLBUSOUT = bus & 0xFB; 00087 } 00088 00096 void input_function_enable_on(){ 00097 char bus = CONTROLBUSIN; 00098 CONTROLBUSOUT = bus | 0x10; 00099 } 00100 00108 void input_function_enable_off(){ 00109 char bus = CONTROLBUSIN; 00110 CONTROLBUSOUT = bus & 0xEF; 00111 } 00112 00120 void deselect_board_on(){ 00121 char bus = CONTROLBUSIN; 00122 CONTROLBUSOUT = bus | 0x08; 00123 } 00124 00132 void deselect_board_off(){ 00133 char bus = CONTROLBUSIN; 00134 CONTROLBUSOUT = bus & 0xF7; 00135 } 00136 00145 void adressingboard(char id){ 00146 adbusoutput(id); 00147 adress_enable_on(); 00148 adress_decode_on(); 00149 adress_decode_off(); 00150 adress_enable_off(); 00151 } 00152 00161 void byteout(char data){ 00162 adbusoutput(data); 00163 output_function_enable_on(); 00164 output_function_enable_off(); 00165 } 00166 00176 char bytein(){ 00177 char inputchar; 00178 setadbustoinput(); 00179 input_function_enable_on(); 00180 inputchar = ADBUSIN; 00181 input_function_enable_off(); 00182 setadbustooutput(); 00183 return inputchar; 00184 } 00185 00193 char singleadconverting(){ 00194 ADCCTL = 0xb8; 00195 while(ADCCTL & 128); 00196 return ADCDH; 00197 } 00198 00208 void dob(char id, char data){ 00209 adressingboard(id); 00210 byteout(data); 00211 } 00212 00221 char dib(char id){ 00222 adressingboard(id); 00223 return bytein(); 00224 } 00225 00235 void aob(char id, char data){ 00236 adressingboard(id); 00237 byteout(data); 00238 } 00239 00247 char aib(){ 00248 int result; 00249 result = singleadconverting(); 00250 return result; 00251 } 00252 00253 /* 00254 void longdelay(){ 00255 if(delaycycles){ 00256 int delay; 00257 for(delay=delaycycles;delay;delay--); 00258 } 00259 } 00260 char nightridertest(){ 00261 char i; 00262 if(i==0){ 00263 i++; 00264 } 00265 i = i<<1; 00266 } 00267 00268 void testcontrols(){ 00269 deselect_board_on(); 00270 adress_enable_on(); 00271 adress_decode_on(); 00272 output_function_enable_on(); 00273 input_function_enable_on(); 00274 deselect_board_off(); 00275 adress_enable_off(); 00276 adress_decode_off(); 00277 output_function_enable_off(); 00278 input_function_enable_off(); 00279 } 00280 */ 00288 void setadcinputs(){ 00289 PHADDR = 0x01; 00290 PHCTL = 0XFF; 00291 PHADDR = 0x02; 00292 PHCTL = 0XFF; 00293 PHADDR = 0x00; 00294 } 00295 00303 void setadbustoinput(){ 00304 PGADDR = 0x01; 00305 PGCTL = 0XFF; 00306 PGADDR = 0x00; 00307 } 00308 00316 void setadbustooutput(){ 00317 PGADDR = 0x01; 00318 PGCTL = 0X00; 00319 PGADDR = 0x00; 00320 } 00321 00329 void bussetup(){ 00330 PEADDR = 0x01; 00331 PECTL = 0X00; 00332 PEADDR = 0x00; 00333 setadbustooutput(); 00334 setadcinputs(); 00335 CONTROLBUSOUT = 0x00; 00336 ADBUSOUT = 0x00; 00337 deselect_board_on(); 00338 deselect_board_off(); 00339 }