romel_emperado
Advanced Member level 2
- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
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 #include <REG51.H> #define adc_port P3 #define adc_out P2 sbit ale=P1^0; //address latch enable sbit oe=P1^3; //output enable sbit sc=P1^1; //start conversion sbit eoc=P1^2; //end of conversion sbit clk=P1^7; // clock sbit ADD_A=P1^4; // Address pins for selecting input channels. sbit ADD_B=P1^5; sbit ADD_C=P1^6; void timer0() interrupt 1 // Function to generate clock of frequency 500KHZ using Timer 0 interrupt. { clk=~clk; } void delay(unsigned int count) // Function to provide time delay in msec. { int i,j; for(i=0;i<count;i++) for(j=0;j<1275;j++); } void select_channel(char c,char b,char a) { ADD_A = a; ADD_B = b; ADD_C = c; } void convert() { delay(1); ale=0; //activate the ale PIN delay(1); ale=1; sc=1; //initaite convertion delay(1); sc=0; delay(1); } void read_adc() { while(eoc == 0); //end of convertion oe = 1; //enable adc output delay(2); oe = 0; } void main() { P2 = 0x00; TMOD = 0x22; //timer0 setting for generating clock of 500KHz using interrupt enable mode. TH0 = 0xFD; IE = 0x82; TR0 = 1; while(1) { select_channel(0,0,1); convert(); read_adc(); } }
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 void timer0() interrupt 1 // Function to generate clock of frequency 500KHZ using Timer 0 interrupt. { clk=~clk; // output clock pulse to p1.7 } void main() { TMOD = 0x22; //timer0 setting for generating clock of 500KHz using interrupt enable mode. TH0 = 0xFD; IE = 0x82; TR0 = 1; while(1); }
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 // Lcd module connections sbit LCD_RS at P2_0_bit; sbit LCD_EN at P2_1_bit; sbit LCD_D4 at P2_2_bit; sbit LCD_D5 at P2_3_bit; sbit LCD_D6 at P2_4_bit; sbit LCD_D7 at P2_5_bit; // End Lcd module connections sbit charging at P2_6_bit; sbit full at P2_7_bit; sbit control at P0_7_bit; float inputa, inputb; //adc config sbit ale at P1_0_bit; //address latch enable sbit oe at P1_3_bit; //output enable sbit sc at P1_1_bit; //start conversion sbit eoc at P1_2_bit; //end of conversion sbit clk at P1_7_bit; // clock sbit ADD_A at P1_4_bit; // Address pins for selecting input channels. sbit ADD_B at P1_5_bit; sbit ADD_C at P1_6_bit; void select_channel(char c,char b,char a) { ADD_A = a; ADD_B = b; ADD_C = c; } void convert() { ale=1; Delay_ms(5); sc=1; Delay_ms(10); sc=0; Delay_ms(1); ale=0; } void read_adc() { while(eoc==0); oe=1; Delay_ms(1); } void get_adc(char x) { select_channel(0,0,x); convert(); read_adc(); read_adc(); if(x==0) inputa = P3; else if(x==1) inputb = P3; } void Timer1InterruptHandler() org IVT_ADDR_ET1 { clk = ~clk; } void main() { float volt_a,volt_b; char txt[15]; char txt2[15]; char x; full = 0; charging = 0; control = 0; ET1_bit = 1; // Enable Timer1 interrupt EA_bit = 1; // Set global interrupt enable GATE1_bit = 0; // Clear this flag to enable Timer1 whenever TR1 bit is set. C_T1_bit = 0; // Set Timer operation: Timer1 counts the divided-down systam clock. TR1_bit = 0; // Turn off Timer1 TMOD = 0x22; TH1 = 0x00; // Set Timer1 high byte TL1 = 0x00; // Set Timer1 low byte TR1_bit = 1; // Run Timer1 Lcd_Init(); // Initialize Lcd Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Cmd(_LCD_CLEAR); // Clear display while(1) { get_adc(0); Delay_ms(90); get_adc(1); x++; if(x==20) { Lcd_Cmd(_LCD_CLEAR); x=0; } //for windmill volatage display volt_a = (( inputa * 5) / 255)* 4; if(inputa<=10) volt_a = 0; FloatToStr(volt_a,txt); Lcd_Out(1,1,"Wind:"); Lcd_Out(1,16,"V"); Lcd_Out(1,7,txt); //for battery display //inputb=164; volt_b = (( inputb * 5) / 255)* 4; if(inputb<=10) volt_b = 0; else if(inputb >= 164) //165 = 12.8v which is battery full { full =1; control = 1; } else if(inputb >= 152) //152 = 11.92v which is battery is discharge { charging = 1; full = 0; } //IntToStr(inputb,txt2); FloatToStr(volt_b,txt2); Lcd_Out(2,1,"Batt:"); Lcd_Out(2,16,"V"); Lcd_Out(2,7,txt2); } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?