⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 一个LCD驱动程序
💻 C
字号:
//*****************************************************************************
//
//  File........: LCD_driver.c
//
//  Author(s)...: ATMEL Norway
//
//  Target(s)...: ATmega169
//
//  Compiler....: IAR EWAAVR 2.27b
//
//  Description.: Main loop and initialization
//
//  Revisions...: 	1.1
//			1.0
//
//  YYYYMMDD - VER. - COMMENT                                       - SIGN.
//
//  20030203 - 1.1  - Modified: CLKPS changed to match ATmega169 rev. C:
//                    Prescaler changed from 1/4 to 1/8 to get 1MHz system
//                    clock from the internal calibrated RC oscillator
//                                                                  - JLL
//
//  20021015 - 1.0  - Created                                       - LHM
//
//*****************************************************************************

//  Include files
#include "Main.h"
#include "Temperature.h"
#include "RTC.h"
#include "UART.h"
#include "Lcd_functions.h"
#include "LCD_driver.h"
#include "Buttons.h"

/******************************************************************************************
*
*   Function name:  main
*
*   returns:        None
*
*   parameters:     None
*
*   Purpose:        Main function which contains the endless main loop
*
******************************************************************************************/
void main(void)
{
    Initialization();       // Call the initialization function

    while(1)                // endless main loop
    {
        Time_update();          // update clock
        
        ADC_conversion();       // measure the temperature
        
        Store_RX_data();        // store data from receivebuffer to SRAM
        
        Send_TX_data();         // load data from SRAM to transmit-buffer and start transmission            

        CheckButtons();         // check if any input from user on the STK500-buttons        

        LCD_update();           // call LCD routine
    }
}

/******************************************************************************************
*
*   Function name:  Initialization
*
*   returns:        None
*
*   parameters:     None
*
*   Purpose:        Initialize the different modules of the ATmega169
*
*******************************************************************************************/
void Initialization(void)
{
    CLKPR = (1<<CLKPCE);        // set Clock Prescaler Change Enable
    CLKPR = (1<<CLKPS1) | (1<<CLKPS0);  // set prescaler = 1/8, Inter RC 8Mhz / 8 = 1Mhz (rev C)
    					// For ATmega169 rev B the prescaler should be 1/4

    CONTRAST = 0x0F;            // set the LCD contrast register to max

    DDRB = 0xF0;                // set PORTB as output to drive the LEDS on STK500

    DDRE = 0x00;                // set PORTE as input to read the SWITCHES on STK500

    PWM_init();                 // initialize Timer1 with PWM    

    RTC_init();                 // start timer2 asynchronous, used for RTC clock

// Select either Single Ended or Differential ADC measurement, comment out the other
    ADC_init(SingleEnded);     // initialize the ADC, select "Single_ended" or "Differential"
//    ADC_init(Differential);     // initialize the ADC, select "Single_ended" or "Differential"

    UART_init(12);              // set up the UART
    
    LCD_Init();                 // initialize the LCD

    LCDsetupData();             // set the display to scroll the init text
    
    __enable_interrupt();       //enable global interrupt    
}

/******************************************************************************************
*
*   Function name:  Delay
*
*   returns:        none
*
*   parameters:     i    
*
*   Purpose:        Delay-routine
*
******************************************************************************************/
void Delay(int i)
{
    int j,k;
    
    for(k=1;k<=i;k++)
    {
        for(j=1;j<=124;j++);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -