📄 main.c
字号:
//*************************************************************************//
// dsPIC30F4011 + UART2 + LCD + Metrix-4x4 KeyPAD + Timer1
// by >> wlasoi@hotmail.com
// Dept. of Physics , Fact. of Science , Ubonrajathanee University
//
// " OpenSource "
//
//**************************************************************************//
#include <p30f4011.h>
#include <stdio.h>
//**************************************************************************//
// Include header Files //
//**************************************************************************//
#include "..\h\main.h"
#include "..\h\delay.h"
#include "..\h\lcd.h"
#include "..\h\uart.h"
#include "..\h\keypad.h"
#include "..\h\timer1.h"
//**************************************************************************//
// Prototype Funtion //
//**************************************************************************//
int main(void)
{
char tempchar[16];
char charIn;
unsigned char keyIn;
OSCCONbits.POST=0; // not post scale (8MHz*16PLL / (1post*4)) = 32
while(OSCCONbits.LOCK!=1) {};
Delay(Delay_50mS_Cnt);
LATE = 0xFFFF;
TRISE = 0x0000;
ADPCFG = 0xFF; //Make analog pins digital
initial_Keypad_port();
init_lcd();
lcd_gotoxy(1,1);
lcd_puts("dsPIC30F4011");
Delay(Delay_1S_Cnt);
clrscr();
lcd_gotoxy(1,1);
InitUART2();
init_uart2_buffer();
uart2_puts("//==================================//\n\r");
uart2_puts("//=========Test dsPIC30F4011========//\n\r");
uart2_puts("//==================================//\n\r");
initial_Timer1();
keyIn = 0;
setSchedualTime_Timer1(100);
while (1)
{
Keypad.keyBusy = 1;
if(is_uart2_char_ready())
{
charIn = uart2_getc();
uart2_putc(charIn);
}
if(Task1FlagCheck(50))
{
//LATEbits.LATE4 ^= 0x01; /Toggle LED's PORT_E4
}
if(KeyFlagCheck(1))
{
if((keyIn = scan_Key()))
{
if(keyIn == 1)
{
clrscr();
keyIn = 0;
sprintf(tempchar,"Wait Press <2>");
lcd_gotoxy(1,1);
lcd_puts(tempchar);
uart2_puts(tempchar);
uart2_puts("\n\r");
Wait_LeaveKeypad();
do{
while(!KeyFlagCheck(1));
keyIn = scan_Key();
}while(keyIn != 2); // 猛 check Key "2" 屯〃摇 loop
sprintf(tempchar," <OK> ");
lcd_gotoxy(1,2);
lcd_puts(tempchar);
uart2_puts(tempchar);
uart2_puts("\n\r");
Wait_LeaveKeypad();
keyIn = 0;
}else{
clrscr();
if(keyIn<=9){
keyIn = 0x30 + keyIn;
}
else{
keyIn = 0x37 + keyIn;
}
sprintf(tempchar,"KeyPress = ");
lcd_gotoxy(1,2);
lcd_puts(tempchar);
lcd_putc(keyIn);
uart2_puts(tempchar);
uart2_putc(keyIn);
uart2_puts("\n\r");
Wait_LeaveKeypad();
keyIn = 0;
}
}
}
}
}
//**************************************************************************//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -