📄 some_test.c
字号:
/*
***********************************************************************
Embest Info&Tech Co., Ltd. All rights reserved.
www.embedinfo.com
***********************************************************************
---------------- file information -------------------------------------
file name: some_test.c
version : v0
author : z.x.q. Embest
begin : 2006-04-10
finish : 2006-04-10
define : some_test file
notes :
---------------- modify information -----------------------------------
version :
modify :
begin :
finish :
define :
-----------------------------------------------------------------------
*/
/*-------------------------------------------------------------------*/
/* include files */
/*---------------------------------------------------------------- --*/
#include "..\..\com\lpc_lib_uart\lpc_lib_uart.h"
#include "..\..\com\lpc_lib_88\lpc_lib_88.h"
#include "..\..\com\lpc_lib_AD\lpc_lib_AD.h"
#include "..\..\com\22eb06_lib_iolamp\22eb06_lib_iolamp.h"
#include "..\..\com\lpc_lib_keyboard\lpc_lib_keyboard.h"
#include "..\..\com\lpc_lib_LCD\lpc_lib_LCD.h"
#include "..\..\com\lpc_lib_IIC\lpc_lib_IIC.h"
#include "..\..\com\lpc_lib_pwm\lpc_lib_pwm.h"
#include "..\..\com\lpc_lib_motor\lpc_lib_motor.h"
/*-------------------------------------------------------------------*/
/* local function declare */
/*-------------------------------------------------------------------*/
void disp_88_test(void);
void AD_test(void);
void led_test(void);
void uart_test(void);
void IIC_test(void);
/*-------------------------------------------------------------------*/
/* extern global variable declare */
/*-------------------------------------------------------------------*/
extern void time_dly(INT32U dly);
/*-------------------------------------------------------------------*/
/* function code */
/*-------------------------------------------------------------------*/
INT32U Main(void)
{
INT8U data;
VICIntEnClr = 0xffffffff; //off all interrupt
VICVectAddr = 0;
VICIntSelect = 0;
lpc_init_pll_manual();
//initialize module controller,it is very necessary for stability of system
spi_data_send(0, 0xfb);
spi_data_send(0, 0x56);
spi_data_send(0, 0xfb);
spi_data_send(0, 0x56);
//initialize LCD,and set some parameter
LCD_reset();
LCD_init();
LCD_BL_con(0);
color_set(0x0,0x07ff); //color setup
posi_set(0,0); //set display position
key_init();
LCD_logo();
while(1)
{
cls(); //clear screen
LCD_printf("Hello,world!\n");
LCD_printf("1:Simple test\n");
LCD_printf("2:COM test\n");
LCD_printf("3:AD buzzer\n");
LCD_printf("4:Motor test\n");
LCD_printf(" input number!");
data=get_key();
cls(); //clear screen
switch(data)
{
case 1: simple_test();
break;
case 2: com_test();
break;
case 3: AD_buzzer();
break;
case 4: motor_con();
break;
default: LCD_printf("error!retry!\n");
time_dly(200);
break;
}
}
/* while(1)
{
cls(); //clear screen
LCD_printf("Hello,world!\n");
LCD_printf("1:8LED test\n");
LCD_printf("2:A/D test\n");
LCD_printf("3:LED test\n");
LCD_printf("4:UART test\n");
LCD_printf("5:IIC test\n");
LCD_printf(" input number!");
data=get_key();
cls(); //clear screen
switch(data)
{
case 1: disp_88_test();
break;
case 2: AD_test();
break;
case 3: led_test();
break;
case 4: uart_test();
break;
case 5: IIC_test();
break;
case 6: switch_test();
break;
case 7: buzzer_test();
break;
case 8: motor();
break;
case 9: LCD_logo();
break;
default: LCD_printf("error!retry!\n");
time_dly(200);
break;
}
}
*/
}
void simple_test(void)
{
INT8U data;
while(1)
{
cls(); //clear screen
LCD_printf("1:LED test\n");
LCD_printf("2:8LED test\n");
LCD_printf("3:SW18/19 test");
LCD_printf("4:LCD logo\n");
LCD_printf("\n any key to main menu!");
data=get_key();
cls(); //clear screen
switch(data)
{
case 1: led_test();
break;
case 2: disp_88_test();
break;
case 3: switch_test();
break;
case 4: LCD_logo();
break;
default: return;
}
}
}
void com_test(void)
{
INT8U data;
while(1)
{
cls(); //clear screen
LCD_printf("1:IIC test\n");
LCD_printf("2:uart0-PC\n");
LCD_printf("3:uart0-uart1\n");
LCD_printf("\n any key to main menu!");
data=get_key();
cls(); //clear screen
switch(data)
{
case 1: IIC_test();
break;
case 2: uart0_pc();
break;
case 3: uart0_uart1();
break;
default: return;
}
}
}
void AD_buzzer(void)
{
INT8U data;
while(1)
{
cls(); //clear screen
LCD_printf("1:AD test\n");
LCD_printf("2:buzzer test\n");
LCD_printf("\n any key to main menu!");
data=get_key();
cls(); //clear screen
switch(data)
{
case 1: AD_test();
break;
case 2: buzzer_test();
break;
default: return;
}
}
}
void motor_con(void)
{
INT8U data;
while(1)
{
cls(); //clear screen
LCD_printf("1:DC motor\n");
LCD_printf("2:Step motor\n");
LCD_printf("any key to main menu!");
data=get_key();
cls(); //clear screen
switch(data)
{
case 1: motor(0);
break;
case 2: motor(1);
break;
default: return;
}
}
}
void disp_88_test(void)
{
INT32U i=0,j;
INT8U data;
LCD_printf("8LED testing\n");
LCD_printf("Press any key!\n");
display_88_init();
while(1)
{
switch(i)
{
case 0: j= 1234567;
break;
case 1: j=12345678;
break;
case 2: j=23456789;
break;
case 3: j=34567890;
break;
case 4: j=45678901;
break;
case 5: j=56789012;
break;
case 6: j=67890123;
break;
case 7: j=78901234;
break;
case 8: j=89012345;
break;
case 9: j=90123456;
break;
default: break;
}
i++;
i=i%10;
display_88(j);
if(moni_key())
break;
time_dly(10);
}
display_88_close();
}
void AD_test(void)
{
INT32U i,data;
LCD_printf("A/D test..\n");
LCD_printf("screw it...\n");
posi_set(6,0);
LCD_printf("Press any key!");
while(1)
{
posi_set(3,0);
AD_init(0,AIN6,0,0);
data=AD_value();
LCD_printf("AIN6: %d ",data);
posi_set(4,0);
AD_init(0,AIN7,0,0);
data=AD_value();
LCD_printf("AIN7: %d ",data);
if(moni_key())
break;
time_dly(60);
}
AD_close();
}
void led_test(void)
{
LCD_printf("LED testing...\nPress any key!\n");
Init_lamp();
while(1)
{
IO_lamp(0, 1);
time_dly(0x80);
IO_lamp(1, 0);
time_dly(0x80);
if(moni_key())
break;
}
IO_lamp(0, 0);
}
void uart0_pc(void)
{
INT8U data;
LCD_printf("uart0 & PC!\n");
LCD_printf("set hyper_terminal..\n57600 8 N 1 N\n");
LCD_printf("any key start");
data=get_key();
cls();
LCD_printf("testing...\n");
LCD_printf("Press any key to quit!\n");
uart0_init(57600); //set baudrate
uart0_printf("\n\nwelcome,:)\n");
uart0_printf("nothing impossible!\n");
uart0_printf("we all are hero!\n\n");
while(1)
{
data=uart0_getkey();
if(data)
{ if(data=='\r')
data='\n';
uart0_sendch(data);
}
if(moni_key())
break;
}
uart0_close();
}
void uart0_uart1(void)
{
INT8U i,data=0;
LCD_printf("uart0 & uart1!");
LCD_printf("testing...\n");
uart0_init(57600); //set uart0 baudrate
uart1_init(57600); //set uart1 baudrate
LCD_printf("uart0 send A~Zuart1 receive\n");
for(i='A';i<'Z';i++)
{
uart0_sendch(i);
time_dly(1);
data=uart1_getkey();
if(data!=i)
{
LCD_printf("error!\n");
break;
}
}
if(i=='Z')
LCD_printf("success!\n");
LCD_printf("any key quit!");
while(1)
{
if(moni_key())
break;
}
uart0_close();
uart1_close();
}
void IIC_test(void)
{
INT8U data[16];
INT8U i;
IIC_init();
LCD_printf("IIC test...\n");
LCD_printf("Writing.. 0~f\n");
for(i=0;i<16;i++)
Wr24C02(0xa0,i,i);
LCD_printf("Reading...\n");
for(i=0;i<16;i++)
{
Rd24C02(0xa0,i,&data[i]);
LCD_printf(" %x",data[i]);
}
LCD_printf("\nPress any key!");
while(1)
{
if(moni_key())
break;
}
}
void switch_test(void)
{ //sw18 and sw19 test
INT32U i;
Init_lamp();
LCD_printf("sw18 and sw19\n");
LCD_printf("press it!\n");
LCD_printf("\n any key quit!");
i = PINSEL2; //set p1.24 p1.25 to gpio
i &= 0xfffffff7;
PINSEL2 = i;
i = IODIR1; //set to input
i &= 0xfcffffff;
IODIR1 = i;
i = IOSET1; //set state as 1
i |= 0x03000000;
IOSET1 = i;
while(1)
{
if(!(IOPIN1 & 0x01000000))
IO_lamp(0, 1);
if(!(IOPIN1 & 0x02000000))
IO_lamp(1, 0);
if(moni_key())
break;
}
IO_lamp(0, 0);
}
void buzzer_test(void)
{
INT32U i,data;
LCD_printf("buzzer test\nscrew AIN6...\nany key quit!");
i = IODIR2; //open buzzer latch
i |= (0x1<<21);
IODIR2 = i;
i = IOCLR2;
i |= (0x1<<21);
IOCLR2 = i;
pwm_init(0,pwm3,1);//init pwm3 to buzzer
pwm_set_f(10); //set lowest frequency as 10Hz
pwm_single_edge(pwm3,10,0.5);
pwm_enable(); //pwm enable
AD_init(0,AIN6,0,0);
while(1)
{
data=AD_value(); //convert AD value to buzzer frequency
data=(data/8)*50+10;
pwm_set_f(data);
pwm_single_edge(pwm3,data,0.5);
if(moni_key())
break;
// time_dly(50);
}
pwm_close();
//close buzzer latch
i = IOSET2;
i |= (0x1<<21);
IOSET2 = i;
}
/*
void motor(void)
{
INT8U type=0;
INT8U mode=0;
motor_init();
//
LCD_printf("input type!\n");
LCD_printf("0:DC 1:step\n");
type=get_key();
LCD_printf("input mode!\n");
LCD_printf("0:deasil\n1:contrarotate\n");
mode=get_key();
cls();
if(type==0)
LCD_printf("DC motor!\n");
else
{
type=1;
LCD_printf("Step motor!\n");
}
if(mode==0)
LCD_printf("Deasil rotate!\n");
else
{
mode=1;
LCD_printf("Contrarotate!\n");
}
while(1)
{
motor_test(type,mode);
if(moni_key())
break;
}
motor_close();
}
*/
void motor(INT8U type)
{
INT8U mode=0;
// LCD_printf("Select motor type!\n");
// LCD_printf("1:DC motor\n2:step motor\n");
LCD_printf("Select rotate mode!\n");
LCD_printf("0:Deasil\n1:Contrarotate\n");
LCD_printf("any key quit!\n");
while(1)
{
mode=get_key();
if(mode==0)
{
cls();
LCD_printf("Deasil rotating...\n");
break;
}
else
if(mode==1)
{
cls();
LCD_printf("Contrarotating...\n");
break;
}
else
return;
}
LCD_printf("any key quit!\n");
motor_init();
while(1)
{
motor_test(type,mode);
if(moni_key())
break;
}
motor_close();
}
void LCD_logo(void)
{
INT32U i;
while(1)
{
DispEm();
for(i=0;i<100000;i++)
if(moni_key())
return;
DispAr();
for(i=0;i<100000;i++)
if(moni_key())
return;
DispArc();
for(i=0;i<100000;i++)
if(moni_key())
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -