📄 main.c
字号:
#include "InAndout.h"
#include "LPC21xx.H"
#include "lcd.h"
extern struct LCD g_lcd;
extern void ShowND( unsigned long data );
extern void InitTime(void);
extern void BeginSet(void);
extern void EndSet(void);
extern int IsSetting(void);
extern void lcd_init(void);
extern void SetCursor( int direction );
extern void Show( int Flag );
extern void DisText( uint8 addr , uint8* p );
void SendDayData(void);
volatile unsigned int g_Buf[ADBUFSIZE];
volatile unsigned int g_CurrentIndex = 0 ;
volatile unsigned char g_band;
volatile int indexOfBuf = 0;
volatile int ADConvert = 1;
void Init()
{
}
void Delay( int dly )
{
int i,j;
for ( i = 0 ; i < dly ; i++ )
{
for( j = 0 ; j < 5000; j++);
}
}
/*
Methed: Scan
To scan the key
and to dispatch the command
*/
int Scan()
{
int i;
PINSEL1 = 0x00;
PINSEL0 = 0x00;
while( 1 )
{
if( ( IOPIN1 & Key_1 ) == 0 ) // key 1 is put down
{
for( i = 0; i < 50000; i++ );
if( ( IOPIN1 & Key_1 ) == 0 )
{
while( ( IOPIN1 & Key_1 ) == 0 );
return 1;
}
}
if( ( IOPIN1 & Key_2 ) == 0 )
{
for( i = 0; i < 50000; i++ );
if( ( IOPIN1 & Key_2 ) == 0 )
{
while( ( IOPIN1 & Key_2 ) == 0 );
return 2;
}
}
if( ( IOPIN1 & Key_3 ) == 0 )
{
for( i = 0; i < 50000; i++ );
if( ( IOPIN1 & Key_3 ) == 0 )
{
while( ( IOPIN1 & Key_3 ) == 0 );
return 3;
}
}
if( ( IOPIN1 & Key_4 ) == 0 )
{
for( i = 0; i < 50000; i++ );
if( ( IOPIN1 & Key_4 ) == 0 )
{
while( ( IOPIN1 & Key_4 ) == 0 );
return 4;
}
}
if( ( IOPIN1 & Key_5 ) == 0 )
{
for( i = 0; i < 50000; i++ );
if( ( IOPIN1 & Key_5 ) == 0 )
{
while( ( IOPIN1 & Key_5 ) == 0 );
return 5;
}
}
if( ( IOPIN1 & Key_6 ) == 0 )
{
for( i = 0; i < 50000; i++ );
if( ( IOPIN1 & Key_6 ) == 0 )
{
while( ( IOPIN1 & Key_6 ) == 0 );
return 6;
}
}
if( ( IOPIN1 & Key_7 ) == 0 )
{
for( i = 0 ; i< 50000; i++ );
if( ( IOPIN1 & Key_7 ) == 0 )
{
while( ( IOPIN1 & Key_7 ) == 0 );
return 7;
}
}
}
// return 0; // never should get here!!
}
void Beep()
{
IODIR0 |= Beep_out;
IOSET0 |= Beep_out;
}
void Beep_off()
{
IOCLR0 |= Beep_out;
}
/*
A/D functions:
Method: AD_convert
*/
unsigned int AD_convert()
{
unsigned int val;
ADCR = 0x002E0401; /* Setup A/D: 10-bit AIN0 @ 3MHz */
ADCR |= 0x01000000; /* Start A/D Conversion */
do {
val = ADDR; /* Read A/D Data Register */
} while ((val & 0x80000000) == 0); /* Wait for end of A/D Conversion */
ADCR &= ~0x01000000; /* Stop A/D Conversion */
val = (val >> 6) & 0x03FF; /* Extract AIN0 Value */
if( val > ADFLUSH )
{
Beep();
}
return val;
}
/*
Timer function:
Method: InitTimer , FunProc_
*/
int g_time = 0;
int g_num = 0;
void __irq Func()
{
int result;
g_time++;
if( g_time == 555000)
{
g_time = 0;
}
if( g_time % 6 != 0 )
{
T0IR = 0x01;
VICVectAddr = 0x00;
return;
}
if( ADConvert == 1 )
{
result = AD_convert();
ShowND( result );
}
result = IsSetting();
if( result == 1 )
{
if( g_num % 2 == 0)
{
Show( 1 );
}
else
{
Show( 0 );
}
g_num++;
if( g_num==1000)
{
g_num = 1;
}
}
else
{
Show( 1 );
}
T0IR = 0x01;
VICVectAddr = 0x00;
}
void InitTimer()
{
// set timer 0 :
T0TC = 0; // Timer clear
T0PR = 99; //200 per hz
T0MCR = 0x03; // Timer 0 mode
T0MR0 = 2500;
T0TCR = 0x03;
T0TCR = 0x01;
// set interrupt here
VICIntSelect = 0x00;
VICVectCntl0 = 0x24;
VICVectAddr0 = (int) Func;
VICIntEnable |= 0x10;
}
/*
*/
void SendDayData(void)
{
}
void SendCurrentData( void )
{
}
void Reset(void)
{
}
uint8 GetStr(void) //Get Data need to think we can not wait here!!
{
while( ! ( U0LSR & 0x01 ) );
return U0RBR;
}
void __irq Func_interupt(void)
{
uint8 ch;
if( 1 )
{
ch = GetStr();
switch( ch )
{
case 0x00:
Reset();
break;
case 0x01:
ADConvert = 0;
SendDayData();
ADConvert = 1;
break;
case 0x02:
ADConvert = 0;
SendCurrentData();
ADConvert = 1;
break;
}
}
}
/*
UTR funtions:
Method: InitUART
*/
void InitUART1(void) // at present use UART1;
{
PINSEL0 |= 0x0005; //Set UART1
U0LCR = 0x83; //8 位数据位, 无奇偶 校验位, 1位停止位
U0DLL = 97 ; //Value Need to reset
U0IER = 0x07;
VICVectAddr1 = (int)Func_interupt;
VICVectCntl1 = 0x12;
VICIntEnable = 0x01;//need to reset;
}
void SendByte( uint8 ch )
{
U1THR = ch;
while( ( U1LSR & 0x80 ) == 0 ) ; //wait for send over
}
void SendStr( uint8* pChar )
{
while(1)
{
if( pChar == '\0' )
{
break;
}
SendByte( *pChar );
pChar++;
}
}
/*
如果要求显示的数据增加:
Method: IncreaseData
*/
void IncreaseData()
{
SetCursor ( Flag_Value_Increase );
}
/*
显示数据减小:
Method: DecreaseData()
*/
void DecreaseData()
{
SetCursor( Flag_Value_Decrease );
}
/*
光标左移:
Method: MoveCurssorLeft()
*/
void MoveCurssorLeft()
{
SetCursor( Flag_Cursor_Move_left );
}
/*
光标右移:
Method: MoveCurssorRight()
*/
void MoveCurssorRight()
{
SetCursor( Flag_Cursor_Move_right );
}
int main(void)
{
int result=1;
lcd_init();
InitTimer();
InitTime();
while(1)
{
result = Scan();
switch( result )
{
case 1:
result = IsSetting();
if( result == 1 )
{
MoveCurssorLeft(); // 光标左移
}
break;
case 2:
result = IsSetting();
if ( result == 1 )
{
MoveCurssorRight(); //光标右移
}
break;
case 3:
result = IsSetting();
if( result == 1 )
{
DecreaseData(); //数据减小
}
break;
case 4:
result = IsSetting();
if( result == 1 )
{
IncreaseData();
}
break;
case 5:
result = IsSetting(); //设置模式 打开 与 关闭
if( result == 1 )
{
EndSet();
}
else
{
BeginSet();
}
break;
case 6:
Beep_off();
break;
case 7:
break;
}
}
// return 0; //Never should get here!!
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -