??? 01/19/05 07:58 Read: times |
#85273 - Saving Code memory |
Hello,
in my 89S53 project I use 4 DS18B20 1-wire sensors. Because I don't want to mess with addressing them, I put them on separate io pins. I have 4 times same routines: reset1, reset2, reset3, reset4, read1...4, write1...4. It works ok, but recently I added some new functions to my project and I got to 12225 bytes, which leaves me only 3 bytes... I want to join those 4 functions, but don't know how. I want to write a common function for all 4 channels like reset_1w (unsigned char channels). I don't think simply using IF statements would do the job because 1-wire communication is time sensitive. Thank you for help! best regards, Damjan Here is a part of my code: sbit SDA1 = P1^0; sbit SDA2 = P1^1; sbit SDA3 = P1^2; sbit SDA4 = P1^3; unsigned char res1_1w () { unsigned char loop, status; SDA1=0; for (loop=0;loop<80;loop++); SDA1=1; loop=10; while (SDA1 && loop--) WCON|=0X02; if (!SDA1) status=1; else status=0; for (loop=0;loop<80;loop++); return(status); } unsigned char res2_1w () { unsigned char loop, status; SDA2=0; for (loop=0;loop<80;loop++); SDA2=1; loop=10; while (SDA2 && loop--) WCON|=0X02; if (!SDA2) status=1; else status=0; for (loop=0;loop<80;loop++); return(status); } unsigned char res3_1w () { unsigned char loop, status; SDA3=0; for (loop=0;loop<80;loop++); SDA3=1; loop=10; while (SDA3 && loop--) WCON|=0X02; if (!SDA3) status=1; else status=0; for (loop=0;loop<80;loop++); return(status); } unsigned char res4_1w () { unsigned char loop, status; SDA4=0; for (loop=0;loop<80;loop++); SDA4=1; loop=10; while (SDA4 && loop--) WCON|=0X02; if (!SDA4) status=1; else status=0; for (loop=0;loop<80;loop++); return(status); } and here is what I want to do: unsigned char reset_1w (unsigned char channel) { unsigned char loop, status; ????(channel)=0; for (loop=0;loop<80;loop++); ????(channel)=1; loop=10; while (????(channel) && loop--) WCON|=0X02; if (!????(channel)) status=1; else status=0; for (loop=0;loop<80;loop++); return(status); } |
Topic | Author | Date |
Saving Code memory | 01/01/70 00:00 | |
Same topic discussed in different thread | 01/01/70 00:00 | |
Existing thread | 01/01/70 00:00 | |
Why so fearful ??? | 01/01/70 00:00 | |
why not multidrop | 01/01/70 00:00 | |
Customer replacement | 01/01/70 00:00 | |
USE ALTERNATIVE PROGRAMMING TECHNIQUE | 01/01/70 00:00 | |
Looking in the wrong place! | 01/01/70 00:00 | |
why not spend another $ | 01/01/70 00:00 | |
use a mask ! | 01/01/70 00:00 | |
Solved![]() | 01/01/70 00:00 |