Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 8000000UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- #include <lcd.h>
- #include <stdlib.h>
- #include <avr/eeprom.h>
- #include <stdio.h>
- #include <math.h>
- char buffer[10];
- char buffer1[10];
- char buffer2[10];
- char buffer3[10];
- char buffer4[10];
- char buffer5[10];
- char buffer6[10];
- volatile uint16_t motor_counter = 0;
- volatile uint16_t delay_counter = 0;
- volatile int MENU;
- volatile float values;
- volatile uint16_t on_timer_value = 5;
- volatile uint16_t off_timer_value = 5;
- volatile float f,ff; // live current load
- volatile float f1 = 2.2; // less than amp float values
- volatile float f2 = 3.0; // greater than amp float values
- volatile uint8_t x = 0, y = 0, z = 0, x1 = 0, ESD = 0;
- ISR(ADC_vect)
- {
- f = ((ADC * 0.0049) - 2.52);
- }
- int main(void)
- {
- DDRB = 0x00; // ALL PORT I/O ARE INPUT
- PORTB = 0b00111111; // ENABLE PULL UP FOR ALL INPUT PINS
- DDRC = 0xEE; // all port c i/o are output, C0 AND C4 ARE INPUT
- PORTC |=(1<<4); // TURN ON PULL FOR PORTC PIN 4 MANUAL START BUTTON
- DDRD = 0XFF; // ALL PORTD OUTPUT DIGITAL
- InitTimer1();
- lcd_init(LCD_DISP_ON);
- lcd_puts("SYSTEM INIT....");
- _delay_ms(500);
- lcd_clrscr();
- lcd_screen_backlight_on();
- // A2D Conversion Initialization
- ADCSRA |= (1 << ADPS2)|(1 << ADPS1); // Set ADC prescalar to 64 @ 8mhz
- ADMUX |= (1 << REFS0); // Set ADC reference to AVCC
- // ADMUX |= (1 << ADLAR); // Left adjust ADC result to allow easy 8 bit reading
- // No MUX values needed to be changed to use ADC0
- ADCSRA |= (1 << ADIE);
- ADCSRA |= (1 << ADFR); // Set ADC to Free-Running Mode
- ADCSRA |= (1 << ADEN); // Enable ADC
- ADCSRA |= (1 << ADSC); // Start A2D Conversions
- // A2D Conversion Initialization
- while(1)
- {
- lcd_gotoxy(0,0);
- lcd_puts("MOTOR CURRENT");
- lcd_gotoxy(0,1);
- ff = f/0.066;
- float avg = 0;
- for(int i=0;i<1000;i++)
- {
- avg = avg + (ff)/1000;
- }
- sprintf(buffer3, "%f", ff);
- lcd_puts(buffer3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement