📄 main.c
字号:
//*****************************************************************************
// File........: main.c
// Author(s)...: ATMEL Norway
// Target(s)...: ATmega169 in Butterfly or STK502
// Compiler....: AVR GCC 20060421
// Description.: Main loop and initialization
// Revisions...: 1.1
// YYYYMMDD - VER. - COMMENT - SIGN.
// 20030326 - 1.0 - Created - AR
// 20060829 - 1.1 - Ported to AVR GCC - TMF, OL
//*****************************************************************************
// Include files
#include <avr/interrupt.h>
#include "Main.h"
#include "LCD_driver.h"
#include "ADC.h"
#include "button.h"
/******************************************************************************************
* Function name: main
* returns: None
* parameters: None
* Purpose: Main function which contains the endless main loop
******************************************************************************************/
int main(void)
{
//Variables
unsigned int Value;
//Initialization
LCD_Init(); // General LCD Initialization Routine from AVR064
ADC_init(LIGHT_SENSOR); // Set ADC Mux to measure on LDR resistor
Button_Init(); // Initialize Button reading, not used in Task1
Value = ADC_read(); //Do initial Measure to initialize Max and Min Values
Value = Value >> 2; // Reduce to 8bit accuracy.
sei(); //enable global interrupt
for(;;) // endless main loop
{
Value = ADC_read(); //reads a value from ADC Depending on ADC Mux setting
Value = Value >> 2; // Reduce to 8bit accuracy.
WriteLCD(Value); // Write the Value to the LCD Buffer otherwise
}
}
/******************************************************************************************
* Function name: WriteLCD
* returns: none
* parameters: Unsigned char
* Purpose: Writes Hex value of temp as BCD value on display
******************************************************************************************/
void WriteLCD( unsigned int Hex )
{
unsigned char Dec_L = 0; //clear decimal-bytes
unsigned char Dec_M = 0; //we need to convert the HEX value to BCD
unsigned char Dec_H = 0;
while(Hex) // loop until the Hex is zero
{
Dec_L = Hex; // store decimal-byte to Dec_L
Hex -= 10; // subtract 10 from the Hex-byte
if(!(SREG & 0x01)) // if carry flag is not set
{
Dec_M++; // incrase Dec_M-byte
if(Dec_M > 9) // if Dec_M-byte over 100 decimal
{
Dec_M = 0; // clear Dec_M
Dec_H++; // increase Dec_H
}
if(!Hex) // if the Hex is zero
Dec_L = 0; // clear Dec_L
}
else
Hex = 0;
}
// Write out Ascii values to LCD Display using functions in LCD_driver.c
Dec_L += 0x30; // add 0x30 to get the rigth ascii-value
LCD_WriteDigit(Dec_L, 7);
Dec_M += 0x30; // add 0x30 to get the rigth ascii-value
LCD_WriteDigit(Dec_M, 6);
Dec_H += 0x30; // add 0x30 to get the rigth ascii-value
LCD_WriteDigit(Dec_H, 5);
LCDCRA |= (1<<LCDIE); //Enable LCD_Start_frame interrupt first when
} //we have new data to write.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -