| ??? 10/15/07 08:10 Read: times |
#145758 - codes Responding to: ???'s previous message |
the added codes are
---------------------------------------------------------------- unsigned char xdata array0H[10]; unsigned char xdata array0L[10]; unsigned int xdata currentIndex; if((currentIndex==NULL) || (currentIndex==10)) { currentIndex =0; } array0H[currentIndex]=ADC0H; array0L[currentIndex]=ADC0L; currentIndex ++; ---------------------------------------------------------------- "Whole codes"
#include <c8051F200.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <intrins.h>
unsigned int q,value,value1,temp,totvalue,e;
unsigned char a,b,c,d;
unsigned char xdata array0H[10];
unsigned char xdata array0L[10];
unsigned int xdata currentIndex;
sbit RS = P2^5; // RS (Register Select) for port 2.5
sbit RW = P2^6; // RW for Port 2.6
sbit E = P2^7; // Enable for Port 2.7
sbit DB0 = P3^0; //DB = Data bus
sbit DB1 = P3^1;
sbit DB2 = P3^2;
sbit DB3 = P3^3;
sbit DB4 = P3^4;
sbit DB5 = P3^5;
sbit DB6 = P3^6;
sbit DB7 = P3^7;
float bit_value,result;
void config(void);
void ldelay(int time);
void enable();
void lcdinit (void);
void lcd_command(unsigned char m);
void print(unsigned char k);
//void hi();
void adcdata();
void voltage();
void result_dsp();
void config(void)
{
// Configure the PRTnMX Registers
PRT0MX = 0x00; // PRT0MX: Initial Reset Value
PRT1MX = 0x00; // PRT1MX: Initial Reset Value
PRT2MX = 0x00; // PRT2MX: Initial Reset Value
// Port configuration (1 = Push Pull Output)
PRT0CF = 0x00; // Output configuration for P0
PRT1CF = 0xFF; // Output configuration for P1
PRT2CF = 0xFF;// Output configuration for P2
PRT3CF = 0xFF; // Output configuration for P3
P0MODE = 0x00; // Input configuration for P0
P1MODE = 0xFF; // Input configuration for P1
P2MODE = 0xFF; //Input configuration for P2
P3MODE = 0xFF; // Input configuration for P3
CPT0CN = 0x00; // Comparator 0 Control Register
CPT1CN = 0x00; // Comparator 1 Control Register
OSCXCN = 0x30; // EXTERNAL Oscillator Control Register
OSCICN = 0x14; // Internal Oscillator Control Register
REF0CN = 0x03; // Reference Control Register
SPI0CN = 0x00; // SPI Control Register
SPI0CFG = 0x00; // SPI Configuration Register
SPI0CKR = 0x00; // SPI Clock Rate Register
SCON = 0x00; // Serial Port Control Register
PCON = 0x00; // Power Control Register
/*----------------
ADC Configuration
-----------------*/
AMX0SL = 0xE7; // AMUX Channel Select Register; Analog input at P0.3 at pin 16
ADC0CF = 0x78; // ADC Configuration Register
ADC0CN = 0x40; // ADC Control Register
ADC0LTH = 0x00; // ADC Less-Than High Byte Register
ADC0GTH = 0x00; // ADC Greater-Than High Byte Register
/*------------------
Timer Configuration
-------------------*/
CKCON = 0x00; // Clock Control Register
TH0 = 0x00; // Timer 0 High Byte
TL0 = 0x00; // Timer 0 Low Byte
TH1 = 0x00; // Timer 1 High Byte
TL1 = 0x00; // Timer 1 Low Byte
TMOD = 0x00; // Timer Mode Register
TCON = 0x00; // Timer Control Register
RCAP2H = 0x00; // Timer 2 Capture Register High Byte
RCAP2L = 0x00; // Timer 2 Capture Register Low Byte
TH2 = 0x00; // Timer 2 High Byte
TL2 = 0x00; // Timer 2 Low Byte
T2CON = 0x00; // Timer 2 Control Register
RSTSRC = 0x00; // Reset Source Register
IE = 0x00; //Interrupt Enable
IP = 0x00; //Interrupt Priority
EIE1 = 0x00; //Extended Interrupt Enable 1
EIE2 = 0x00; //Extended Interrupt Enable 2
EIP1 = 0x00; //Extended Interrupt Priority 1
EIP2 = 0x00; //Extended Interrupt Priority 2
// Watchdog Timer Configuration
WDTCN=0xde; //disable software
WDTCN=0xad; //watchdog timer
}
void ldelay (int time)
{
long y;
for (y=0; y<time;y++)
{
}
}
void enable()
{
E = 1;
ldelay(5);
E = 0;
ldelay(5);
}
void lcdinit(void)
{
E=0;
RW=0;
RS=0;
P3=0x38; // 8bit, 2 lines, default font
enable();
P3=0x0C; // on display
enable();
P3=0x06; // entry mode, not to shift
enable();
P3=0x01; // clear dispay and cursor return
enable();
P3=0x02; // cursor return
enable();
}
void lcd_command(unsigned char m)
{
P3 = m;
RS = 0;
RW = 0;
enable();
}
void print(unsigned char k)
{
P3 = k;
RS = 1;
RW = 0;
enable();
}
void voltage()
{
unsigned char words[] = "Voltage:";
for(q=0;q<9;q++) //9 characters stored
{
print (words[q]);
}
}
{
ADCINT = 0;
value=0;
ADBUSY = 1;
// ldelay(100);
while(ADCINT==0); //Is conversion complete ?
if((currentIndex==NULL) || (currentIndex==10))
{
currentIndex =0;
}
array0H[currentIndex]=ADC0H;
array0L[currentIndex]=ADC0L;
currentIndex ++;
value = ADC0L;
e= ADC0H;
totvalue= value + (e*256);
// ldelay(100);
// ldelay(100);
ADCINT=0;
ADBUSY=0;
}
void bit_resolution()
{
bit_value = 3.0/(4096);
result = totvalue*bit_value;
}
void one() /*convert 1st value A.xxx */
{
temp=result;
temp = temp%10;
a = temp+48;
}
void dec1() /*convert 1st decimal place value x.Bxx */
{
temp=result*10;
temp = temp%10;
b = temp+48;
}
void dec2() /*convert 2nd decimal place value x.xCx */
{
temp = result*100;
temp = temp%10;
c = temp+48;
}
void dec3() /*convert 3rd decimal place value x.xxD */
{
temp = result*1000;
temp = temp%10;
d = temp+48;
}
void convert_all()
{
one();
dec1();
dec2();
dec3();
}
void displayD() /* display 3 digit number */
{
RS = 1;
P3 = a;
enable();
print(0x2E); /*display ".", ASCII code is 2E for "."*/
P3 = b;
enable();
P3 = c;
enable();
P3 = d;
enable();
}
void result_dsp()
{
bit_resolution();
convert_all();
displayD();
}
void main()
{
config();
lcdinit(); //Initialize LCD
ADCEN = 1; //Enable ADC
ldelay(50);
lcd_command(0x80); //LCD command to display on the first line
voltage(); //Display "Voltage="
lcd_command(0x02); //LCD command to return the cursor home
lcd_command(0xC0); //LCD command to display on the second line
adcdata();
result_dsp();
print(0x56); //Display "V"
ldelay(4000);
}
|
| Topic | Author | Date |
| 8051 in C programming | 01/01/70 00:00 | |
| Read the manual! | 01/01/70 00:00 | |
| Not in Keil | 01/01/70 00:00 | |
| an old IAR compiler | 01/01/70 00:00 | |
| is there any fundamental problem... | 01/01/70 00:00 | |
| The C language | 01/01/70 00:00 | |
| structures | 01/01/70 00:00 | |
| A Non Standard Extension | 01/01/70 00:00 | |
| just don't use it | 01/01/70 00:00 | |
| Similar problem | 01/01/70 00:00 | |
| Time | 01/01/70 00:00 | |
| Read The Manual (sometimes abbreviated to RTFM)! | 01/01/70 00:00 | |
| silicon laboratories | 01/01/70 00:00 | |
| Compiler? | 01/01/70 00:00 | |
| no. | 01/01/70 00:00 | |
| actually | 01/01/70 00:00 | |
| Aside: Keil | 01/01/70 00:00 | |
| You are using Keil! | 01/01/70 00:00 | |
| yes... | 01/01/70 00:00 | |
| Learn to walk first! | 01/01/70 00:00 | |
| FYP | 01/01/70 00:00 | |
| 12 Weeks | 01/01/70 00:00 | |
| in parts | 01/01/70 00:00 | |
| That's what I said | 01/01/70 00:00 | |
| (As) I Understand It (now) ;-) | 01/01/70 00:00 | |
| Misreading | 01/01/70 00:00 | |
| No problem :-) | 01/01/70 00:00 | |
| the beauty of posting twice | 01/01/70 00:00 | |
| error | 01/01/70 00:00 | |
| include | 01/01/70 00:00 | |
| probably best not to... | 01/01/70 00:00 | |
| but why? | 01/01/70 00:00 | |
| Because | 01/01/70 00:00 | |
| solved | 01/01/70 00:00 | |
| Textbook time! | 01/01/70 00:00 | |
| undefined identifier | 01/01/70 00:00 | |
| typedefs of types for shorthand | 01/01/70 00:00 | |
| Shorthand vs. Portability | 01/01/70 00:00 | |
| Plus | 01/01/70 00:00 | |
| Be careful | 01/01/70 00:00 | |
| The concise C spec | 01/01/70 00:00 | |
| Plus plus | 01/01/70 00:00 | |
| Another one - Certainty! | 01/01/70 00:00 | |
| then, define your stdstdint.h | 01/01/70 00:00 | |
| shorthand can be VERY useful | 01/01/70 00:00 | |
| hi...back | 01/01/70 00:00 | |
| RTFM! | 01/01/70 00:00 | |
| Two books you need | 01/01/70 00:00 | |
| no book in hand yet | 01/01/70 00:00 | |
| You need those books! | 01/01/70 00:00 | |
| :P | 01/01/70 00:00 | |
| meaning | 01/01/70 00:00 | |
| In glorious technicolor... | 01/01/70 00:00 | |
| Back to K&R | 01/01/70 00:00 | |
| ... but if you put it into the context of a... | 01/01/70 00:00 | |
| Cool Colors | 01/01/70 00:00 | |
| what about the other '51/mcu Cs? | 01/01/70 00:00 | |
| pedantic | 01/01/70 00:00 | |
| ya.. | 01/01/70 00:00 | |
| higher resolution ADC | 01/01/70 00:00 | |
| ADC fundamentals | 01/01/70 00:00 | |
| Hi-Res ADC is pointless with poor input circuitry! | 01/01/70 00:00 | |
| 4 bits! | 01/01/70 00:00 | |
| Time for a new thread! | 01/01/70 00:00 | |
| xdata | 01/01/70 00:00 | |
| Re-post the code & fully describe the situation | 01/01/70 00:00 | |
| Block Comment style | 01/01/70 00:00 | |
| codes | 01/01/70 00:00 | |
| Not quite | 01/01/70 00:00 | |
| no idea | 01/01/70 00:00 | |
| analog input | 01/01/70 00:00 | |
| how ? | 01/01/70 00:00 | |
| Noob doc | 01/01/70 00:00 | |
| there is no such thing | 01/01/70 00:00 | |
| Already covered | 01/01/70 00:00 | |
| Andy, I'm amazed | 01/01/70 00:00 | |
| no | 01/01/70 00:00 | |
| The link works | 01/01/70 00:00 | |
| PDF Document | 01/01/70 00:00 | |
| program added | 01/01/70 00:00 | |
| I'm not sure what you're asking? | 01/01/70 00:00 | |
| is it? | 01/01/70 00:00 | |
| What?? | 01/01/70 00:00 | |
| ok | 01/01/70 00:00 | |
| Post your code properly! | 01/01/70 00:00 | |
| Why read twice? | 01/01/70 00:00 | |
| how? | 01/01/70 00:00 | |
| Accessing arrays | 01/01/70 00:00 | |
| some hints | 01/01/70 00:00 | |
| sfr16 | 01/01/70 00:00 | |
| Did that | 01/01/70 00:00 | |
| re SFR16 | 01/01/70 00:00 | |
| Naing Linn really needs to learn to do it himsel | 01/01/70 00:00 | |
Thanks | 01/01/70 00:00 | |
| 8 to 16 bit | 01/01/70 00:00 |



