freemanantony
Member level 4

- Joined
- May 19, 2010
- Messages
- 70
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Chennai, India
- Activity points
- 2,005
hai every one ,
i am using C8051350 for reading voltage and writing to dac proportional to input voltage to adc,while reading adc section is commented code is working other wise code hangs here i am including my code can any one help me
i am using C8051350 for reading voltage and writing to dac proportional to input voltage to adc,while reading adc section is commented code is working other wise code hangs here i am including my code can any one help me
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 #include<c8051F350.h> #include<math.h> sfr16 ADC0DEC = 0x9A; // ADC0 Decimation Ratio Register #define SYSCLK 24500000 // System clock frequency in Hz #define MDCLK 2457600 // Modulator clock in Hz (ideal is // (2.4576 MHz) #define OWR 20 // Desired Output Word Rate in Hz unsigned char present_voltage = 0; void OSCILLATOR_Init (void); void adc_init(void); void dac_init(void); void port_init(void); void initialise(); void read_adc(); void delay(); /*@@@@@@@@@@@@@@@@@@@@@ OSCILLATOR INITIALIZATION @@@@@@@@@@@@@@@@@@@@@@*/ void OSCILLATOR_Init (void) { unsigned char delay1 = 100; OSCICN |= 0x03; // Configure internal oscillator for // its maximum frequency RSTSRC = 0x04; // Enable missing clock detector // the SYSTEMCLOCK source } /******************** ADC INITIALIZATION*********************/ void adc_init(void) { REF0CN |= 0x01; ADC0CN = 0x00; ADC0CF = 0x00; ADC0CLK = (SYSCLK/MDCLK)-1; ADC0DEC = ((unsigned long) MDCLK / (unsigned long) OWR / (unsigned long) 128) - 1; ADC0BUF = 0x00; ADC0MUX = 0x08; ADC0MD = 0x83; } /******************** DAC INITIALIZATION*********************/ void dac_init(void) { IDA0CN = 0xF3; IDA1CN = 0xF3; //REF0CN |= 0x01; } /******************** PORT INITIALIZATION*********************/ void port_init(void) { // P0MDOUT |= 0x00; // Enable UTX as push-pull output //P0 = 0xFF; P1MDOUT |= 0xC0; // All P1 pins open-drain output //P1 &= 0x0A; P2MDOUT |= 0x00; // Make the LED (P2.2) a push-pull // output /*P3MDOUT = 0x00; P3 = 0X00; P4MDOUT = 0x00; P4 = 0;*/ XBR0 = 0x00; // Enable UART on P0.4(TX) and P0.5(RX) XBR1 = 0x00; // Enable crossbar and weak pull-ups P0SKIP = 0XFF; P1SKIP = 0XFF; } /******************* INITIALIZATION *********************/ void initialise() { OSCILLATOR_Init(); port_init(); adc_init(); dac_init(); EIE1 = 0x00; EA = 0; } /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ void read_adc() { //while(AD0BUSY); while(!AD0INT); // Wait till conversion complete AD0INT = 0; // Clear ADC0 conversion complete flag present_voltage = ADC0L; present_voltage = ADC0M; present_voltage = ADC0H; } /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ void delay() { unsigned char i,j; for(j=0x00;j<=0x7f;j++) { for(i=0x00;i<=0x7f;i++) { } } } /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ // MAIN CODE /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ void main (void) { PCA0MD &= ~0x40;//disable watchdog timer initialise(); AD0INT = 0; //present_voltage = 0x22; while(1) { read_adc(); // delay(); IDA1 = ((present_voltage)*(0x02)); //IDA1 = (present_voltage); //delay(); //IDA1 = 0x90; } }
Last edited by a moderator: