📄 main.c
字号:
// $Id: Main.c,v 1.7 2007/01/24 21:44:15 tprescott Exp $
/*****************************************************
Project : Main.c
Date :
Author : Toby Prescott
Company : Atmel
Comments:
Chip type : ATmega128
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 1024
Revisions:
v1.0 - Started for CodeVision
v2.6 - Clean for WinAVR
*****************************************************/
#include <avr/io.h>
#include <string.h>
#include <avr/pgmspace.h>
#include "atml_Lcd.h"
#include "atml_Message.h"
#include "rfid_Sleep.h"
#include "rfid_UserIO.h"
#include "rfid_LCDMenu.h"
#include "rfid_rtcMenu.h"
#include "rfid_PCMenu.h"
#include "rfid_RFIDMenu.h"
#include "rfid_U2270.h"
#include "rfid_Rtc.h"
#include "rfid_Uart.h"
// Declare your global variables here
int main(void)
{
// Declare your local variables here
unsigned char currentPos=0, nextPos=0;
// char *compile_date = __DATE__;
// char *compile_time = __TIME__;
// Input/Output Ports initialization
PORTA=0xFF;
DDRA=0x00;
PORTB=0xFF;
DDRB=0xE0;
PORTC=0xFF;
DDRC=0x40;
PORTD=0xFD;
DDRD=0xE6;
PORTF=0xF7;
DDRF=0x0E;
#if defined (__AVR_ATmega128__)//mega128 pinout
PORTE=0xCF;
DDRE=0x00;
PORTG=0xFF;
DDRG=0x07;
#elif defined (__AVR_AT90USB1287__)//usb1287 pinout
PORTE=0xFF;
DDRE=0x07;
#endif
asm("sei"); // Turn on global Interrupts
rtc_Init();
#if defined (__AVR_ATmega128__)//mega128
if((PINE & PWRDETECT128) == 0) //Check that PWR switch is on
#elif defined (__AVR_AT90USB1287__)//usb1287
if((PINC & PWRDETECT1287) == 0) //Check that PWR switch is on
#endif
{
slp_EnterSleep(); //If PWR switch is off, got to sleep
}
else{;} //else continue startup
U2270_InitReader();
lcd_Init_Display(); //Setup the display complete with stored settings
lcd_Write_Display(CMD,ALL_POINTS_OFF); //Will wake from sleep mode if applicable
lcd_erase(); //Clear the LCD memory
upDate = 0;
while (1)
{
// Menu Display
if(currentPos != nextPos || upDate == 0)
{
currentPos = nextPos;
// Place your code here
lcd_clear_area(SCRN_LEFT,SCRN_TOP,SCRN_RIGHT,SCRN_BOTTOM); // Clear LCD
lcd_box(SCRN_LEFT,SCRN_TOP,SCRN_RIGHT,SCRN_BOTTOM); // Draw Boarder
//**** Add Menu text ****//
lcd_put_fString(4, 2, PSTR("RFID"));
lcd_put_fString(37, 2, PSTR("PC"));
lcd_put_fString(55, 2, PSTR("RTC"));
lcd_put_fString(80, 2, PSTR("Display"));
//**** Add highlighting to current position text ****//
if(currentPos == 0){lcd_invert_area(3, 1, 27 , 10);}
else if(currentPos == 1){lcd_invert_area(36, 1, 48 , 10);}
else if(currentPos == 2){lcd_invert_area(54, 1, 72 , 10);}
else if(currentPos == 3){lcd_invert_area(79, 1, 121 , 10);}
lcd_box(SCRN_LEFT,SCRN_TOP,SCRN_RIGHT,10);
lcd_put_Atmel_Logo(35, 20); // Draw Atmel Logo
lcd_put_fString(93,35,PSTR("RFID")); // Add text
lcd_put_fString(9,45,PSTR("Everywhere You Are")); // Add corporate phrase
lcd_put_fString(95,55,PSTR("v2.6")); // Add Revision
lcd_update(SCRN_TOP,SCRN_BOTTOM);
}
// End display
uio_Get();
switch(currentPos){ // Process inputs by postion
case 0: // RFID
if(cButton == IO_UP){;}
else if(cButton == IO_DOWN || cButton == IO_ENTER)
{
rfidMenu_Display(); // Call RFID menu routine
upDate = 0; // Update LCD Display request
}
else if(cButton == IO_RIGHT){nextPos = 1;}
break;
case 1: // PC
if(cButton == IO_UP){;}
else if(cButton == IO_DOWN || cButton == IO_ENTER)
{
pcMenu_Display(); // Call PC menu routine
upDate = 0; // Update LCD Display request
}
else if(cButton == IO_RIGHT){nextPos = 2;}
else if(cButton == IO_LEFT){nextPos = 0;}
break;
case 2: // RTC
if(cButton == IO_UP){;}
else if(cButton == IO_DOWN || cButton == IO_ENTER)
{
rtcMenu_Display(); // Call RTC menu routine
upDate = 0; // Update LCD Display request
}
else if(cButton == IO_RIGHT){nextPos = 3;}
else if(cButton == IO_LEFT){nextPos = 1;}
break;
case 3: // Display
if(cButton == IO_UP){;}
else if(cButton == IO_DOWN || cButton == IO_ENTER)
{
LCDMenu_Display(); // Call Display menu routine
upDate = 0; // Update LCD Display request
}
else if(cButton == IO_LEFT){nextPos = 2;}
break;
default:
break;
}
if(cButton){uio_Release();}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -