//--------------------------------------------------------------------------------------- // Programm Nr.: 11 // Content : ADC (single conversion) on pressing a key + output 10-bit on LCD // : two int->ascii for lcd routines with leading zero subpression // Author : digital AG Halle // Date : 27.07.2008 // System : ATmega8-16PU - Dai Hoc Hue Development Board //--------------------------------------------------------------------------------------- //--included Files----------------------------------------------------------------------- #include #include //--declarations------------------------------------------------------------------------- #ifndef F_CPU #define F_CPU 8000000 //CPU frequency = 8 MHz #endif #define LCD_PORT PORTD #define LCD_DDR DDRD #define LCD_RS 0x04 #define LCD_EN 5 void lcd_enable(void); //setup communication to the lcd void lcd_data(unsigned char temp1); //send a byte to the lcd void lcd_clear(void); //erase all displayed signs void lcd_init(void); //initialise lcd void set_cursor(uint8_t x, uint8_t y); //set cursor to position x,y void lcd_string(char *data); //send a string to the lcd void messure(); //ADC routine to catch a 10-bit value void output(uint8_t proc); //general output routine void processing1(uint16_t value,uint8_t row); //lcd output routine void processing2(uint16_t value,uint8_t row); //lcd output routine with leading zero subpression uint8_t KEYS; uint8_t KEYS_OLD; uint8_t proced; uint16_t result; //16 bit value for the 10-Bit result of the ADC messure uint32_t voltage; //32 bit calculation variable //--MAIN PROGRAMM------------------------------------------------------------------------ int main(void) { //--INITIALISATION--------------------------------------------------------------- //ADC_INIT: ADMUX |= (1<> 4; temp1 = temp1 & 0x0F; LCD_PORT &= 0xF0; LCD_PORT |= temp1; // set lcd_enable(); temp2 = temp2 & 0x0F; LCD_PORT &= 0xF0; LCD_PORT |= temp2; // set lcd_enable(); _delay_us(42); } void lcd_command(unsigned char temp1) //send a command to the lcd { unsigned char temp2 = temp1; LCD_PORT &= ~(1<> 4; // get high nibble temp1 = temp1 & 0x0F; // mask LCD_PORT &= 0xF0; LCD_PORT |= temp1; // set lcd_enable(); temp2 = temp2 & 0x0F; // get and mask low nibble LCD_PORT &= 0xF0; LCD_PORT |= temp2; // set lcd_enable(); _delay_us(42); } void lcd_enable(void) //send the enable puls to the lcd { LCD_PORT |= (1<