Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/16/05 14:22
Read: times


 
Msg Score: -1
 -1 Gimmee Code
#87650 - Bipom Voltage Meter
I am in dire need of someone to please help me or give me code for a voltage meter programmed in MicroC for the 8051 Bipom board. I have posted already and appreciate the help but am still stuck. Please look over code and tell me or fix whats wrong or provide me with code that will work. Many thanks in advance.

#include <8051io.h>
#include <8051bit.h> /* Bit set/clear macros */
#include <8051reg.h>
#define CLK P1.6
#define CS P3.7
#define DI P1.4
#define DO P1
#define RS P0.0 // LCD register select bit
#define RW P0.1 // LCD read/write bit
#define EN P0.2 // LCD enable bit
//function prototypes
void clock(void);
unsigned char convert(unsigned char channel);
void Init_CPU(void);
void Initial_LCD(void); // Initialization function
void EN_low(void); //Set EN to low position function
void LCD_putc(unsigned char key); // Display single character function
void LCD_puts(const unsigned char *str);// Display character string function
void execute(void);//executes a 1 second delay and initializes the LCD
//main starts here
void main()
{
unsigned char STEP;
Initial_LCD(); // Run function Initial_LCD
Init_CPU(); //do all initializations
STEP=convert(0);
while(STEP==0)
{
LCD_puts("Hook up voltage source");
execute();
delay(2000);
LCD_puts(".");
delay(2000);
LCD_puts(".");
delay(2000);
LCD_puts(".");
delay(2000);
LCD_puts(".");
delay(2000);
execute();
}
execute();
if(STEP==1)
{
LCD_puts("10 mV");
execute();
}
if(STEP==2)
{
LCD_puts("20 mV");
execute();
}
if(STEP==3)
{
LCD_puts("30 mV");
execute();
}
if(STEP==4)
{
LCD_puts("40 mV");
execute();
}
if(STEP==5)
{
LCD_puts("50 mV");
execute();
}
if(STEP==6)
{
LCD_puts("60 mV");
execute();
}
if(STEP==7)
{
LCD_puts("70 mV");
execute();
}
if(STEP==8)
{
LCD_puts("80 mV");
execute();
}
if(STEP==9)
{
LCD_puts("90 mV");
execute();
}
if(STEP==10||STEP==11)
{
LCD_puts("100 mV");
execute();
}
if(STEP==12||STEP==13)
{
LCD_puts("120 mV");
execute();
}
if(STEP==14||STEP==15)
{
LCD_puts("140 mV");
execute();
}
if(STEP==16||STEP==17)
{
LCD_puts("160 mV");
execute();
}
if(STEP==18||STEP==19)
{
LCD_puts("180 mV");
execute();
}
if(STEP==20||STEP==21)
{
LCD_puts("200 mV");
execute();
}
if(STEP==22||STEP==23)
{
LCD_puts("220 mV");
execute();
}
if(STEP==24||STEP==25)
{
LCD_puts("240 mV");
execute();
}
if(STEP==26||STEP==27)
{
LCD_puts("260 mV");
execute();
}
if(STEP==28||STEP==29)
{
LCD_puts("280 mV");
execute();
}
if(STEP==30||STEP==31)
{
LCD_puts("300 mV");
execute();
}
if(STEP==32||STEP==33)
{
LCD_puts("314 mV");
execute();
}
if(STEP==34||STEP==35)
{
LCD_puts("333 mV");
execute();
}
if(STEP==36||STEP==37)
{
LCD_puts("353 mV");
execute();
}
if(STEP==38||STEP==39)
{
LCD_puts("373 mV");
execute();
}
if(STEP==40||STEP==41)
{
LCD_puts("392 mV");
execute();
}
if(STEP==42||STEP==43)
{
LCD_puts("412 mV");
execute();
}
if(STEP==44||STEP==45)
{
LCD_puts("431 mV");
execute();
}
if(STEP==46||STEP==47)
{
LCD_puts("451 mV");
execute();
}
if(STEP==48||STEP==49)
{
LCD_puts("471 mV");
execute();
}
if(STEP==50||STEP==51)
{
LCD_puts("488 mV");
execute();
}
if(STEP==52||STEP==53)
{
LCD_puts("507 mV");
execute();
}
if(STEP==54||STEP==55)
{
LCD_puts("521 mV");
execute();
}
if(STEP==56||STEP==57)
{
LCD_puts("541 mV");
execute();
}
if(STEP==58||STEP==59)
{
LCD_puts("560 mV");
execute();
}
if(STEP==60||STEP==61)
{
LCD_puts("581 mV");
execute();
}
if(STEP==62||STEP==63)
{
LCD_puts("601 mV");
execute();
}
if(STEP==64||STEP==65)
{
LCD_puts("624 mV");
execute();
}
if(STEP==66||STEP==67)
{
LCD_puts("644 mV");
execute();
}
if(STEP==68||STEP==69)
{
LCD_puts("664 mV");
execute();
}
if(STEP==70||STEP==71)
{
LCD_puts("682 mV");
execute();
}
if(STEP==72||STEP==73)
{
LCD_puts("701 mV");
execute();
}
if(STEP==74||STEP==75)
{
LCD_puts("720 mV");
execute();
}
if(STEP==76||STEP==77)
{
LCD_puts("739 mV");
execute();
}
if(STEP==78||STEP==79)
{
LCD_puts("759 mV");
execute();
}
if(STEP==80||STEP==81)
{
LCD_puts("784 mV");
execute();
}
if(STEP==82||STEP==83)
{
LCD_puts("798 mV");
execute();
}
if(STEP==84||STEP==85)
{
LCD_puts("818 mV");
execute();
}
if(STEP==86||STEP==87)
{
LCD_puts("837 mV");
execute();
}
if(STEP==88||STEP==89)
{
LCD_puts("856 mV");
execute();
}
if(STEP==90||STEP==91)
{
LCD_puts("876 mV");
execute();
}
if(STEP==92||STEP==93)
{
LCD_puts("896 mV");
execute();
}
if(STEP==94||STEP==95)
{
LCD_puts("906 mV");
execute();
}
if(STEP==96||STEP==97)
{
LCD_puts("916 mV");
execute();
}
if(STEP==98||STEP==99)
{
LCD_puts("935 mV");
execute();
}
if(STEP==100||STEP==101)
{
LCD_puts("974 mV");
execute();
}
if(STEP==102||STEP==103)
{
LCD_puts("994 mV");
execute();
}
if(STEP==104||STEP==105)
{
LCD_puts("1.01 V");
execute();
}
if(STEP==106||STEP==107)
{
LCD_puts("1.03 V");
execute();
}
if(STEP==108||STEP==109)
{
LCD_puts("1.05 V");
execute();
}
if(STEP==110||STEP==111)
{
LCD_puts("1.07 V");
execute();
}
if(STEP==112||STEP==113)
{
LCD_puts("1.09 V");
execute();
}
if(STEP==114||STEP==115)
{
LCD_puts("1.11 V");
execute();
}
if(STEP==116||STEP==117)
{
LCD_puts("1.13 V");
execute();
}
if(STEP==118||STEP==119)
{
LCD_puts("1.15 V");
execute();
}
if(STEP==120||STEP==121)
{
LCD_puts("1.17 V");
execute();
}
if(STEP==122||STEP==123)
{
LCD_puts("1.19 V");
execute();
}
if(STEP==124||STEP==125)
{
LCD_puts("1.20 V");
execute();
}
if(STEP==126||STEP==127)
{
LCD_puts("1.22 V");
execute();
}
if(STEP==128||STEP==129)
{
LCD_puts("1.24 V");
execute();
}
if(STEP==130||STEP==131)
{
LCD_puts("1.26 V");
execute();
}
if(STEP==132||STEP==133)
{
LCD_puts("1.28 V");
execute();
}
if(STEP==134||STEP==135)
{
LCD_puts("1.30 V");
execute();
}
if(STEP==136||STEP==137)
{
LCD_puts("1.32 V");
execute();
}
if(STEP==138||STEP==139)
{
LCD_puts("1.34 V");
execute();
}
if(STEP==140||STEP==141)
{
LCD_puts("1.36 V");
execute();
}
if(STEP==142||STEP==143)
{
LCD_puts("1.38 V");
execute();
}
if(STEP==144||STEP==145)
{
LCD_puts("1.40 V");
execute();
}
if(STEP==146||STEP==147)
{
LCD_puts("1.42 V");
execute();
}
if(STEP==148||STEP==149)
{
LCD_puts("1.43 V");
execute();
}
if(STEP==150||STEP==151)
{
LCD_puts("1.45 V");
execute();
}
if(STEP==152||STEP==153)
{
LCD_puts("1.47 V");
execute();
}
if(STEP==154||STEP==155)
{
LCD_puts("1.49 V");
execute();
}
if(STEP==156||STEP==157)
{
LCD_puts("1.51 V");
execute();
}
if(STEP==158||STEP==159)
{
LCD_puts("1.53 V");
execute();
}
if(STEP==160||STEP==161)
{
LCD_puts("1.55 V");
execute();
}
if(STEP==162||STEP==163)
{
LCD_puts("1.57 V");
execute();
}
if(STEP==164||STEP==165)
{
LCD_puts("1.59 V");
execute();
}
if(STEP==166||STEP==167)
{
LCD_puts(" 1.61V");
execute();
}
if(STEP==168||STEP==169)
{
LCD_puts("1.63 V");
execute();
}
if(STEP==170||STEP==171)
{
LCD_puts("1.65 V");
execute();
}
if(STEP==172||STEP==173)
{
LCD_puts("1.67 V");
execute();
}
if(STEP==174||STEP==175)
{
LCD_puts("1.69 V");
execute();
}
if(STEP==176||STEP==177)
{
LCD_puts("1.71 V");
execute();
}
if(STEP==178||STEP==179)
{
LCD_puts("1.73 V");
execute();
}
if(STEP==180||STEP==181)
{
LCD_puts("1.75 V");
execute();
}
if(STEP==182||STEP==183)
{
LCD_puts("1.77 V");
execute();
}
if(STEP==184||STEP==185)
{
LCD_puts("1.79 V");
execute();
}
if(STEP==186||STEP==187)
{
LCD_puts("1.81 V");
execute();
}
if(STEP==188||STEP==189)
{
LCD_puts("1.83 V");
execute();
}
if(STEP==190||STEP==191)
{
LCD_puts("1.85 V");
execute();
}
if(STEP==192||STEP==193)
{
LCD_puts("1.87 V");
execute();
}
if(STEP==194||STEP==195)
{
LCD_puts("1.89 V");
execute();
}
if(STEP==196||STEP==197)
{
LCD_puts("1.91 V");
execute();
}
if(STEP==198||STEP==199)
{
LCD_puts("1.93 V");
execute();
}
if(STEP==200||STEP==201)
{
LCD_puts("1.95 V");
execute();
}
if(STEP==202||STEP==203)
{
LCD_puts("1.97 V");
execute();
}
if(STEP==204||STEP==205)
{
LCD_puts("1.99 V");
execute();
}
if(STEP==206||STEP==207)
{
LCD_puts("2.01 V");
execute();
}
if(STEP==208||STEP==209)
{
LCD_puts("2.03 V");
execute();
}
if(STEP==210||STEP==211)
{
LCD_puts("2.04 V");
execute();
}
if(STEP==212||STEP==213)
{
LCD_puts("2.06 V");
execute();
}
if(STEP==214||STEP==215)
{
LCD_puts("2.08 V");
execute();
}
if(STEP==216||STEP==217)
{
LCD_puts("2.10 V");
execute();
}
if(STEP==218||STEP==219)
{
LCD_puts("2.12 V");
execute();
}
if(STEP==220||STEP==221)
{
LCD_puts("2.14 V");
execute();
}
if(STEP==222||STEP==223)
{
LCD_puts("2.16 V");
execute();
}
if(STEP==224||STEP==225)
{
LCD_puts("2.18 V");
execute();
}
if(STEP==226||STEP==227)
{
LCD_puts("2.20 V");
execute();
}
if(STEP==228||STEP==229)
{
LCD_puts("2.22 V");
execute();
}
if(STEP==230||STEP==231)
{
LCD_puts("2.24 V");
execute();
}
if(STEP==232||STEP==233)
{
LCD_puts("2.26 V");
execute();
}
if(STEP==234||STEP==235)
{
LCD_puts("2.28 V");
execute();
}
if(STEP==236||STEP==237)
{
LCD_puts("2.29 V");
execute();
}
if(STEP==238||STEP==239)
{
LCD_puts("2.31 V");
execute();
}
if(STEP==240||STEP==241)
{
LCD_puts("2.34 V");
execute();
}
if(STEP==242||STEP==243)
{
LCD_puts("2.36 V");
execute();
}
if(STEP==244||STEP==245)
{
LCD_puts("2.38 V");
execute();
}
if(STEP==246||STEP==247)
{
LCD_puts("2.39 V");
execute();
}
if(STEP==248||STEP==249)
{
LCD_puts("2.41 V");
execute();
}
if(STEP==250||STEP==251)
{
LCD_puts("2.43 V");
execute();
}
if(STEP==252||STEP==253)
{
LCD_puts("2.45 V");
execute();
}
if(STEP==254||STEP==255)
{
LCD_puts("2.47 V");
execute();
}
printf("channel 0 = %dn",convert(0));
}//end main
//define Init_CPU()
void Init_CPU(void)
{
serinit(9600); //initialize serial port
clrbit(CS); //CS is output to ADC
clrbit(CLK); //CLK is clock to ADC
} //end of Init_CPU()

//define function clock
void clock(void)
{
setbit(CLK);
clrbit(CLK);
}

//define function convert
unsigned char convert(unsigned char channel)
{
//variable declaration
unsigned char i, value;
unsigned char option;

//before first clock initial state
clrbit(CLK);
setbit(CS);
clrbit(DI);

//1st clock
clrbit(CS);
setbit(DI);
clock();
delay(1);

//2nd clock
setbit(DI);
clock();
delay(1);

//3rd and 4th clocks
option=channel;
switch(option)
{
case 0: //channel 0
clrbit(DI); //3rd clock
clock();
delay(1);
clrbit(DI); //4th clock
clock();
delay(1);
break;

case 1: //channel 1
setbit(DI); //3rd clock
clock();
delay(1);
clrbit(DI); //4th clock
clock();
delay(1);
break;

case 2: //channel 2
setbit(DI); //3rd clock
clock();
delay(1);
clrbit(DI); //4th clock
clock();
delay(1);
break;

case 3: //channel 3
setbit(DI); //3rd clock
clock();
delay(1);
clrbit(DI); //4th clock
clock();
delay(1);
break;
} //end switch

setbit(DI); //DI is input
clock(); //5th clock
delay(1); //wait for MUX to settle

//start clocking in to 8051 the converted digital calue from MSB
value=0; //00000000 Binary
for(i=0; i<8; i++) //clock 6, to clock 13
{
if(DO&0x10)
value=value|1;
clock();
if(i<7)
value=value<<1;
} //end for

for(i=0; i<8; i++)
{
clock();
}//end of for
return value;
} //end convert()

void Initial_LCD(void) // Function initializes LCD
{
P0=0; // Make all bits on port 0 output bits
delay(40); // 20 ms delay
P0=0x34; // Block 1
EN_low();
delay(10);
P0=0x34; // Block 2
EN_low();
P0=0x34; // Block 3
EN_low();
P0=0x24; // Block 4
EN_low();
P0=0x24; // Block 5
EN_low();
P0=0x64; // Block 6
EN_low();
P0=0x04; // Block 7
EN_low();
P0=0x84; // Block 8
EN_low();
P0=0x04; // Block 9
EN_low();
P0=0x14; // Block 10
EN_low();
P0=0x04; // Block 11
EN_low();
P0=0x64; // Block 12
EN_low();
P0=0x04; // Block 13
EN_low();
P0=0xE4; // Block 14
EN_low();
}

void EN_low(void) // Set EN to low position, done with procedure
{
delay(1); // Create 0.5 ms delay
clrbit(EN); // set EN to low position
delay(5); // Create 2.5 ms delay
}

void LCD_putc(unsigned char key)
{
unsigned char value1, value2; // Create variables value1, value2
value1=key&0xF0; // Use OR function to separate low nibble out
value1=value1|0x05; // Use AND function to make low nibble 5
P0=value1; // Send out high nibble
EN_low();
value2=key&0x0F; // Use OR function to separate high nibble out
value2=value2<<4; // Shift low nibble bits to high nibble position
value2=value2|0x05; // Use AND function to make low nibble 5
P0=value2; // Send out low nibble
EN_low();
}

void LCD_puts(const unsigned char *str)
{
register unsigned char char1; // Create registered variable char1
while ((char1=*str++)) // While next character in the string is not null …
{
LCD_putc(char1); // Run function LCD_putc with input "char1"
}
}

void execute(void)
{
delay(2000);
Initial_LCD();
}


List of 18 messages in thread
TopicAuthorDate
Bipom Voltage Meter            01/01/70 00:00      
   So, whats wrong            01/01/70 00:00      
   it would be nice            01/01/70 00:00      
   and ...            01/01/70 00:00      
      deja vu!            01/01/70 00:00      
         all over again            01/01/70 00:00      
   No other ideas ?            01/01/70 00:00      
      nasty            01/01/70 00:00      
         True.            01/01/70 00:00      
   LAck of knowledge            01/01/70 00:00      
      try this            01/01/70 00:00      
      Programming ?            01/01/70 00:00      
         arrays            01/01/70 00:00      
            truth, nothing but and the WHOLE truth            01/01/70 00:00      
            ?            01/01/70 00:00      
      Questions            01/01/70 00:00      
   try            01/01/70 00:00      
   split it            01/01/70 00:00      

Back to Subject List