📄 mcs51-项目开发经典.c
字号:
else if(strstr(uart_buffer, "@TEST-93C46#") != NULL)
{test_command =TEST_93C46;
}
else if(strstr(uart_buffer, "@SET-SD2000:") != NULL)//判断是否包含"@SET-SD2000:"字符串
{//设置时钟的命令格式如下:@SET-SD2000:年,月,日,星期,时,分,秒#
test_command =SET_SD2000;
uart_receive_data = uart_buffer;//通过指针处理串口接收的字串
uart_receive_data = uart_receive_data + 12;//去掉字符串中 @SET-SD2000: 部分
get_data(uart_receive_data);//从字符串中提取data数据并放在temporary_data[]临时数组中
year = change_hex_to_bcd(temporary_data[0]%100);
month = change_hex_to_bcd(temporary_data[1]);
date = change_hex_to_bcd(temporary_data[2]);
week = change_hex_to_bcd(temporary_data[3]);
hour = change_hex_to_bcd(temporary_data[4]);
minute = change_hex_to_bcd(temporary_data[5]);
second = change_hex_to_bcd(temporary_data[6]);
}
else if(strstr(uart_buffer, "@READ-SD2000#") != NULL)
{test_command =READ_SD2000;
}
else if(strstr(uart_buffer, "@TEST-LCM-8BIT#") != NULL)
{test_command =TEST_LCM;
lcm_control_mode=8;
LCM_LED=0;
}
else if(strstr(uart_buffer, "@TEST-LCM-3BIT#") != NULL)
{test_command =TEST_LCM;
lcm_control_mode=3;
LCM_LED=0;
}
else if(strstr(uart_buffer, "@TEST-18B20#") != NULL)
{test_command =TEST_18B20;
}
else if(strstr(uart_buffer, "@TEST-HD7279#") != NULL)
{test_command =TEST_HD7279;
}
else if(strstr(uart_buffer, "@TEST-BIT-IO#") != NULL)
{test_command =TEST_BIT_IO;
FM_OUT =0;//蜂鸣器响
for(t1_delay_time=0;t1_delay_time<4;);//延时500毫秒
FM_OUT =1;//蜂鸣器停
}
else if(strstr(uart_buffer, "@TEST-TLC2543#") != NULL)
{test_command =TEST_TLC2543;
}
else if(strstr(uart_buffer, "@TEST-TLC5617:") != NULL)
{//设置时钟的命令格式如下:@TEST-TLC5617:da_data#
//da_data的取值范围:0-1024 ,对应输出电压:0-5V
test_command =TEST_TLC5617;
uart_receive_data = uart_buffer;//通过指针处理串口接收的字串
uart_receive_data = uart_receive_data + 14;//去掉字符串中 @TEST-TLC5617: 部分
get_data(uart_receive_data);//从字符串中提取data数据并放在temporary_data[]临时数组中
da_out_data = temporary_data[0];
}
else if(strstr(uart_buffer, "@TEST-L297#") != NULL)
{test_command =TEST_L297;
}
else if(strstr(uart_buffer, "@TEST-DC-MOTOR#") != NULL)
{test_command =TEST_DC_MOTOR;
}
uart_receive_ok = 0;
ES = 1;//允许uart0中断
}
//-------------------------------------------------------------------------------------------------
//---------------------- 对各项功能进行调试 -------------------------------------
//-------------------------------------------------------------------------------------------------
switch(test_command)
{//-----------------------------------------
case TEST_74HC595://1
{ctrl_74hc595(0x00);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(~0x01);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(~0x02);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(~0x04);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(~0x08);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(~0x10);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(~0x20);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(~0x40);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(~0x80);
for(t1_delay_time=0;t1_delay_time<4;);
ctrl_74hc595(0xff);
for(t1_delay_time=0;t1_delay_time<4;);
break;
}
//-----------------------------------------
case TEST_24C02://2
{uart_string_out("The data write to 24C02:");//将0-127数据写入24C02的0-127地址
uart_newline(1);
for(i=0;i<128;i++)
{sendbyte_24c02(i,i);
uart_data_decimalist_out(i);
uart_space(1);
}
uart_newline(1);
uart_string_out("The data read from 24C02:");//从24C02的0-127地址读取数据
uart_newline(1);
for(i=0;i<128;i++)
{uart_data_decimalist_out(readbyte_24c02(i));
uart_space(1);
}
uart_newline(2);
test_command=0;//串口设置一次调试24C02命令,只进行一次读写24C02操作,因为24C02有擦写次数限制
break;
}
//-----------------------------------------
case TEST_93C46://3
{uart_string_out("The data write to 93C46:");//将0-127数据写入24C02的0-127地址
uart_newline(1);
ERAL();//擦除芯片全部内容
for(i=0;i<64;i++)
{WRITE_93C46(i,i*2+10000);
uart_data_decimalist_out(i*2+10000);
uart_space(1);
}
uart_newline(1);
uart_string_out("The data read from 93C46:");//从24C02的0-127地址读取数据
uart_newline(1);
for(i=0;i<64;i++)
{uart_data_decimalist_out(READ_93C46(i));
uart_space(1);
}
uart_newline(2);
test_command=0;//串口设置一次调试93C46命令,只进行一次读写93C46操作,因为93C46有擦写次数限制
break;
}
//-----------------------------------------
case SET_SD2000://4
{set_sd2000();
test_command=0;
break;
}
//-----------------------------------------
case READ_SD2000://5
{read_sd2000_ys();
if(old_second!=second)
{old_second=second;
uart_string_out("The time now is:");
if(year>9) uart_string_out("20");
else uart_string_out("200");
uart_data_decimalist_out(change_bcd_to_hex(year));//时钟数据是DCD码,需要转换成HEX
uart_byte_out(':');
uart_data_decimalist_out(change_bcd_to_hex(month));
uart_byte_out(':');
uart_data_decimalist_out(change_bcd_to_hex(date));
uart_byte_out(':');
uart_data_decimalist_out(change_bcd_to_hex(week));
uart_byte_out(':');
uart_data_decimalist_out(change_bcd_to_hex(hour));
uart_byte_out(':');
uart_data_decimalist_out(change_bcd_to_hex(minute));
uart_byte_out(':');
uart_data_decimalist_out(change_bcd_to_hex(second));
uart_newline(1);
break;
}
}
//-----------------------------------------???
case TEST_18B20://6
{break;
}
//-----------------------------------------
case TEST_HD7279://7
{HD7279_Initial();
for(i=0;i<10;i++) //数码管测试
{HD7279_ShowData(1,i,1);
HD7279_ShowData(2,i,1);
HD7279_ShowData(3,i,1);
HD7279_ShowData(4,i,1);
HD7279_ShowData(5,i,1);
HD7279_ShowData(6,i,1);
HD7279_ShowData(7,i,1);
HD7279_ShowData(8,i,1);
if(key_value_main!=0xff)//如果有按键触发则如下
{uart_string_out("You have pushed the button S");
uart_byte_out(change_hex_to_askii(key_value_main));
uart_newline(1);
key_value_main=0xff;//使用完本次触发的键值后必须清空键值,否则主程序认为在连续触发该键
}
for(t1_delay_time=0;t1_delay_time<10;);//延时500毫秒
uart_byte_out('A');
}
HD7279_SendByte( HD7279_RESET );//复位
break;
}
//-----------------------------------------
case TEST_BIT_IO://8
{if(BIT_IN==0)
{uart_string_out("The state of bit_input is LOW");
uart_newline(1);
}
else
{uart_string_out("The state of bit_input is HIGH");
uart_newline(1);
}
if(VOLT_IN==0)
{uart_string_out("The state of volt_input is LOW");
uart_newline(1);
}
else
{uart_string_out("The state of volt_input is HIGH");
uart_newline(1);
}
test_command=0;//查询一次就报告一次这两路输入信号的电平状态
break;
}
//-----------------------------------------
case TEST_TLC2543://9
{//通过AD芯片读取测试点PCB-T2点的电压(T2点电压值由R51和R38这两个电位计调整),并串口显示
//此时可以用万用表测量PCB-T2点的电压,与串口显示的电压进行比较
ad_total=0;
ad2543_measure(7);//祛除上一次转换结果并启动本次转换
for(i=0;i<10;i++)//10次测量求和
{ad_mesure_data =ad2543_measure(7);
ad_total+=ad_mesure_data;
}
ad_total = ad_total/10;//取10次测量均值
//计算,将TLC2543测得的AD量转化成对应于基准的电压,注意电压值带小数点
ad_total = ad_total/4096*5;
//将电压值显示到计算机屏幕上,保留两位小数
uart_string_out("The volt of test point (T2) is :");
ad_mesure_data =(uint)(ad_total*100);//保留2位小数
uart_byte_out(change_hex_to_askii(ad_mesure_data/100));//串口传输整数部分
uart_byte_out('.');//串口传输小数点
uart_byte_out(change_hex_to_askii((ad_mesure_data%100)/10));//串口传输小数点后第1位
uart_byte_out(change_hex_to_askii(ad_mesure_data%10));//串口传输小数点后第2位
uart_newline(1);
test_command=0;
break;
}
//-----------------------------------------
case TEST_TLC5617://10
{//观测串口设定的DA数据
uart_string_out("The data write to TLC5617 is :");
uart_data_decimalist_out(da_out_data);
uart_newline(1);
//计算并显示对应输入数据应该输出的电压
uart_string_out("The volt out from TLC5617 should be :");
ad_total =(float)(da_out_data)/1024*2.5*2;//计算对应的DA输出电压
ad_mesure_data =(uint)(ad_total*100);//保留2位小数
uart_byte_out(change_hex_to_askii(ad_mesure_data/100));//串口传输整数部分
uart_byte_out('.');//串口传输小数点
uart_byte_out(change_hex_to_askii((ad_mesure_data%100)/10));//串口传输小数点后第1位
uart_byte_out(change_hex_to_askii(ad_mesure_data%10));//串口传输小数点后第2位
uart_newline(1);
//OUTA、OUTB同时输出串口设定的 da_data 数值
TLC5617_Write(3,da_out_data);//缓冲器写
TLC5617_Write(1,da_out_data);//OUTA、OUTB同时输出
//用TLC2543测量OUTB输出的电压,并通过串口显示
ad_total=0;
ad2543_measure(8);//祛除上一次转换结果并启动本次转换
for(i=0;i<10;i++)//10次测量求和
{ad_mesure_data =ad2543_measure(8);
ad_total+=ad_mesure_data;
}
ad_total = ad_total/10;//取10次测量均值
//计算,将TLC2543测得的AD量转化成相应的电压,注意电压值带小数点
uart_string_out("The volt of TLC5617_OUTB (T6) is :");
ad_total = ad_total/4096*5;
ad_mesure_data =(uint)(ad_total*100);//保留两位小数
uart_byte_out(change_hex_to_askii(ad_mesure_data/100));//串口传输整数部分
uart_byte_out('.');//串口传输小数点
uart_byte_out(change_hex_to_askii((ad_mesure_data%100)/10));//串口传输小数点后第1位
uart_byte_out(change_hex_to_askii(ad_mesure_data%10));//串口传输小数点后第2位
//可以用万用表测量 TLC5617_OUTA(T5) 点的电压,与串口显示的OUTB电压进行比较
uart_newline(1);
test_command=0;
break;
}
//-----------------------------------------
case TEST_L297://12
{
RST_L297 =0;//L297复位
for(t1_delay_time=0;t1_delay_time<1;);
RST_L297 =1;//复位结束
for(t1_delay_time=0;t1_delay_time<1;);
CW_L297 =1;//方向
HF_L297 =1;//1-半步、0-全步
E_L297 =1;//允许L297输出
for(wqy1=0;wqy1<3000;wqy1++)
{
CLK_L297 =1;//步进脉冲高电平
for(wqy2=0;wqy2<200;wqy2++);
CLK_L297 =0;//步进脉冲低电平
for(wqy2=0;wqy2<200;wqy2++);
//CLK_L297 =1;//步进脉冲高电平
//for(t1_delay_time=0;t1_delay_time<40;);
}
for(i=0;i<5;i++)
{ctrl_74hc595(0x00);
for(t1_delay_time=0;t1_delay_time<5;);
ctrl_74hc595(0xff);
for(t1_delay_time=0;t1_delay_time<5;);
}
CW_L297 =0;//方向
for(wqy1=0;wqy1<3000;wqy1++)
{
CLK_L297 =1;//步进脉冲高电平
for(wqy2=0;wqy2<200;wqy2++);
CLK_L297 =0;//步进脉冲低电平
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -