📄 main.c.bak
字号:
#include "RS232.h"
#include "KeyPad.h"
#include "LCD.h"
#include "Timer.h"
#include "RTC.h"
#include "MState.h"
#include "ADC.h"
#include "Flash.h"
#include "GLib.h"
#include "FileSys.h"
#include "Config.h"
#include "44b.h"
//////////////////////////////////
void Test_LowPwr(void)
{
//Mode_LowPwr();
}
extern struct KEY_struct KEY_inf;
///////////////////////////////
void Test_KeyPad(void)
{
//Key_open();
//Timer_open();
unsigned char k;
while(1){
k = Key_get();
if(k) RS232_send_char(k);
}
}
extern unsigned char COM_FrameBuf[];
void Test_Com(void)
{
int num;
int i;
while(1)
{
num = COM_frame_get();
if( num ){
for(i=0;i<num;i++) { RS232_send_char( COM_FrameBuf[i] ); }
}
}
}
////////////////////////////
unsigned char ADC_get(void)
{
unsigned short i;
rCLKCON |= (1<<12);
for(i = 0; i < 300; i++);
rADCPSR = 250;
rADCCON = 0x1 | (0<<2); //Start Conversion
while(rADCCON &0x1); //To avoid The first FLAG error case.
//(The START bit is cleared in one ADC clock.)
while(!(rADCCON & 0x40));
for(i=0;i<rADCPSR;i++); //To avoid The second FLAG error case
i = rADCDAT & 0x3FF;
RS232_send_char(i>>8);
RS232_send_char(i);
i = (i-0x16E)/12 + 30;
rCLKCON &= ~(1<<12);
return i;
}
extern void LCD_pain_batt(unsigned char Value);
////////////////////////////////
void Test_RTC(void)
{
int i,j;
struct RTC_struct RTC_inf;
//struct RTC_struct *pRTC;
RTC_inf.Year = 0x07;
RTC_inf.Mon = 0x12;
RTC_inf.Day = 0x06;
RTC_inf.Week = 0x04;
RTC_inf.Hour = 0x21;
RTC_inf.Min = 0x57;
RTC_inf.Sec = 0x00;
//pRTC = RTC_inf;
RTC_set( &RTC_inf );
while(1){
for(i=0; i<1000; i++){
for(j=0; j<10000; j++);
}
RTC_get( &RTC_inf );
RS232_send_char(0x11);//=
RS232_send_char(RTC_inf.Year);//Year
//RS232_send_char(0x3A);//:
RS232_send_char(RTC_inf.Mon);
//RS232_send_char(0x3A);
RS232_send_char(RTC_inf.Day);
//RS232_send_char(0x3A);
RS232_send_char(RTC_inf.Week);
//RS232_send_char(0x3A);
RS232_send_char(RTC_inf.Hour);
//RS232_send_char(0x3A);
RS232_send_char(RTC_inf.Min);
//RS232_send_char(0x3A);
RS232_send_char(RTC_inf.Sec);
//RS232_send_char(0x3A);
}
}
#define TEST_START 0x600000
#define TEST_1 0x601000
#define TEST_2 0x602000
#define TEST_3 0x603000
//-----flash test-----
void Flash_test(void)
{
struct CONFIG_struct Config_inf;
unsigned short check;
unsigned int rt,i;
unsigned char *pTmp;
//unsigned short Msg[16];
unsigned short Msg;
//check = 0;
//Config_inf_erase(1);
//Config_inf_erase(2);
//RS232_send_char('0');
//Flash_type_get();
//
//while(1);
//Flash_chip_reset();
Flash_sector_erase( TEST_1 );
for(rt=0; rt<256; rt++)
{
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
Flash_word_program( 0x7FFF,(TEST_1+(rt<<1)) );
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
Flash_word_program( 0x3FFF,(TEST_1+(rt<<1)) );
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
Flash_word_program( (rt|(1<<12)),(TEST_1+(rt<<1)) );
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
}
while(1);
for(rt=0; rt<2048; rt++){
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
}
Flash_sector_erase( TEST_1 );
for(rt=0; rt<2048; rt++){
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
}
for(rt=0; rt<2048; rt++){
Flash_word_program( rt,(TEST_1+(rt<<1)) );
}
for(rt=0; rt<2048; rt++){
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
}
Flash_sector_erase( TEST_1 );
for(rt=0; rt<2048; rt++){
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
}
for(rt=0; rt<2048; rt++){
Flash_word_program( ~rt,(TEST_1+(rt<<1)) );
}
for(rt=0; rt<2048; rt++){
Msg = *( (volatile unsigned short *)(TEST_1+(rt<<1)) );
RS232_send_char( Msg>>8 );
RS232_send_char( Msg );
}
while(1);
// while(1){
//
// //Msg[0] = *((volatile unsigned short *)(0x700000+0) );
// //if( Msg[0] == 0xFFFF ) RS232_send_char( '1' );
//
// //RS232_send_char('A');
// //setor_erase( 0x700000 );
//
// //if( Key_get() == KEY_F2 ){
//
// RS232_send_char('A');
// Config_inf_erase(1);
//
// RS232_send_char('B');
// Config_inf.Flag = 0xCCCC;
// Config_inf.LCD_const = 4;
// Config_inf.Print_deep = 4;
// Config_inf.Pswd[0] = '1';
// Config_inf.Pswd[1] = '2';
// Config_inf.Pswd[2] = '3';
// Config_inf.Pswd[3] = '4';
// Config_inf.Pswd[4] = '5';
// Config_inf.Pswd[5] = '6';
//
// check = Crc16( (unsigned char *)(&Config_inf), 12 );
//
// Config_inf.Crc = check;
//
// //RS232_send_char('C');
// rt = Config_inf_write(&Config_inf);
//
// //RS232_send_char('D');
// rt = Config_inf_read(&Config_inf);
//
// if( rt ){
// //RS232_send_char('E');
// pTmp = (unsigned char *)(&Config_inf);
//
// //for(rt=0;rt<16;rt++) RS232_send_char( *(pTmp++) );
//
// }
//
// //KEY_inf.Value = 0;
//
// //RS232_send_char('F');
// //}
//
// }
}
//--------------------
void Config_test(void)
{
struct CONFIG_struct Config_inf;
int rt,i;
unsigned char *pTmp;
pTmp = (unsigned char *)( &Config_inf );
rt = Config_inf_read( &Config_inf );
if(rt>=0){
RS232_send_string("Config get :: ");
RS232_send_char( rt );
RS232_send_string("inf == ");
for(i=0;i<32;i++) RS232_send_char( pTmp[i] );
}
for(i=0;i<32;i++) pTmp[i] = i+'A';
Config_inf_save( (rt+1),&Config_inf );
rt = Config_inf_read( &Config_inf );
if(rt>=0){
RS232_send_string("Config get :: ");
RS232_send_char( rt );
for(i=0;i<32;i++) RS232_send_char( pTmp[i] );
}
while(1){
;
}
}
unsigned char FName[11]={'t','e','s','t',' ',' ',' ',' ','t','x','t'};
extern unsigned char COM_TransBuf[];
void FS_test(void)
{
unsigned char msg[100];
int i,j,rt,fd,num;
struct FILE_struct File_inf;
unsigned char *pMsg;
unsigned char myname[11] = {0x52,0x41,0x4d,0x4c,0x4f,0x41,0x44,0x20,0x42,0x49,0x4e};
//FS_format();
FS_init();
rt = File_delete( myname );
if(rt>=0){
RS232_send_string(" file delete OK !");
}else{
RS232_send_string(" delete error !!!");
}
//while(1);
num = 6;
for(i=0;i<6;i++)
{
j = File_inf_get(i,&File_inf);
if( j >= 0 )
{
pMsg = (unsigned char *)(&File_inf);
for(j=0;j<32;j++){
COM_TransBuf[ num++ ] = pMsg[j];
}
//for(j=0;j<32;j++) RS232_send_char( pMsg[j] );
//num++;
}
}
num = (num-6)/32;
COM_TransBuf[3] = 0x52;
COM_TransBuf[4] = 0x01;
COM_TransBuf[5] = num; //--->> file num
//--->>if no file, this is 0x00,len is 3
//for(i=0;i<32;i++) COM_TransBuf[i+6] = FileDir_1[i];
//for(i=0;i<32;i++) COM_TransBuf[i+38] = FileDir_2[i];
//COM_TransBuf[5] = 2;
COM_frame_send( num*32+3 );
while(1);
for(i=0;i<6;i++)
{
j = File_inf_get(i,&File_inf);
if(j >= 0 ){
RS232_send_string("dir_msg==");
pMsg = (unsigned char *)(&File_inf);
for(j=0;j<32;j++) RS232_send_char( pMsg[j] );;
}
}
while(1);
fd = File_create(FName);
if(fd >= 0){
RS232_send_char('A');
}
fd = File_open(FName);
if(fd >= 0){
RS232_send_char('B');
}else{
RS232_send_char('E');
RS232_send_char('R');
RS232_send_char('R');
}
for(i=0;i<100;i++)
{
for(j=0;j<100;j++) msg[j] = i;
//File_seek(fd,(i*100),0);
rt = File_write(fd,msg,100);
//File_read(fd,msg,100);
//for(j=0;j<100;j++) RS232_send_char(msg[j]);
}
RS232_send_char('C');
File_close(fd);
FS_init();
fd = File_open(FName);
if(fd >= 0){
RS232_send_char('D');
}else{
RS232_send_char('E');
RS232_send_char('R');
RS232_send_char('R');
}
if(fd >= 0)
{
for(i=0;i<100;i++)
{
//for(j=0;j<100;j++) msg[j] = i;
File_seek(fd,(i*100),1);
//rt = File_write(fd,msg,100);
File_read(fd,msg,100);
for(j=0;j<100;j++) RS232_send_char(msg[j]);
}
}
while(1);
}
///////////////////////////////
int Main(void)
{
unsigned char k;
struct RTC_struct RTC_inf;
rSYSCFG = 0;
rINTMSK |= BIT_GLOBAL;
StartTest:
//RS232_open(115200,COM_8BIT|COM_NOPARITY|STOP_1BIT);
LCD_open();
Key_open();
RS232_open(115200,COM_8BIT|COM_NOPARITY|STOP_1BIT);
//Timer_open();
RTC_open();
LCD_clear_screen();
//LCD_locate(1,6); LCD_write_string("功能测试",1);
//LCD_locate(6,4); LCD_write_string("[1] 中断测试",0);
//LCD_locate(8,4); LCD_write_string("[2] 低功耗测试",0);
//LCD_locate(10,4); LCD_write_string("[3] 串口测试",0);
LCD_face();
MState_open();
RTC_inf.Year = 0x07;
RTC_inf.Mon = 0x12;
RTC_inf.Day = 0x06;
RTC_inf.Week = 0x04;
RTC_inf.Hour = 0x21;
RTC_inf.Min = 0x57;
RTC_inf.Sec = 0x00;
RTC_set( &RTC_inf );
k = ADC_batt();
FS_init();
rINTMSK &=~(BIT_GLOBAL);
//rINTMSK |= BIT_GLOBAL;
//Flash_test();
//FS_test();
Config_test();
// LCD_clear_screen();
// while(1)
// {
// k = Key_get();
//
// if( (k>='0') && (k<='7') ){
// LCD_pain_progress(8,0,7,(k-0x30));
// }
//
// }
MState_handle();
//Test_Com();
//Test_RTC();
//Test_KeyPad();
while(1){
if(KEY_inf.Value == KEY_ENTER){
RS232_send_char(0x11);
RS232_send_char(KEY_inf.Value);
KEY_inf.Value = 0;
RS232_send_char(0x22);
k = ADC_get();
RS232_send_char(0x33);
RS232_send_char(k);
RS232_send_char(0x44);
LCD_pain_batt(k);
}
}
//Test_PWM();
//Test_EINT4567();
RS232_open(115200,COM_8BIT|COM_NOPARITY|STOP_1BIT);
//Timer5_init();
Test_Com();
goto StartTest;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -