【转】嵌入式中的查表法

本文介绍了一种利用查表法实现复杂程序的方法,并通过一个具体的C++程序示例展示了如何遍历二维数组并根据特定条件终止循环。该程序使用了Windows API中的Sleep函数来实现延迟效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



   今天就说一说查表法,如果在程序中运用查表法,不论多么复杂的程序,只要符合一张表,那都可以实现,非常简单,体力活而已,接下来看看下面这个程序,对上面这个进行操作吧。

  1. #include <stdio.h>  
  2. #include <windows.h>  
  3. //这里的行可以自由写,这样就不受限制,想做出什么样的效果都可以。  
  4. int array[][10] =  {  
  5.   
  6.     0x03,0x00,0x00,0x00,0x00,//第一列  
  7.     0x00,0x02,0x00,0x00,0x00,  
  8.       
  9.     0x0C,0x00,0x00,0x00,0x00,//第二列  
  10.     0x00,0x04,0x00,0x00,0x00,  
  11.       
  12.     0x10,0x00,0x00,0x00,0x00,//第三列  
  13.     0x00,0x08,0x00,0x00,0x00,  
  14.       
  15.     0x60,0x00,0x00,0x00,0x00,//第四列  
  16.     0x00,0x10,0x00,0x00,0x00,  
  17.       
  18.     0x80,0x01,0x00,0x00,0x00,//第五列  
  19.     0x00,0x20,0x00,0x00,0x00,  
  20.       
  21.     0xAA,0x55,0x00,0x00,0xC0,//end  
  22.     0x00,0x00,0x00,0x00,0x00,  
  23.       
  24. };  
  25.   
  26. void to_Q112_cmd_designator_LED(int *array)  
  27. {  
  28.     int i;  
  29.     for(i = 0; i < 10; i++)  
  30.     {  
  31.         printf(" %3d ", *(array+i));      
  32.     }  
  33.     printf("\n");  
  34. }  
  35.   
  36. void delay_500ms(void)  
  37. {  
  38.     Sleep(500);  
  39. }  
  40.   
  41. int main(void)  
  42. {  
  43.     int i,j;  
  44.     int tick;  
  45.     int count = 0;  
  46.     while(array[count][0] != 0xAA || array[count][1] != 0x55)//如果当数组第count行第0列等于0xAA,或者第count行第1列等于0x55时,那么就退出,否则就循环执行遍历数据   
  47.     {     
  48.         to_Q112_cmd_designator_LED((int *)(&array[0][0]+count*10) );//以首元素每次向后偏移10个字节  
  49.         delay_500ms();  
  50.           
  51.         count++;  
  52.     }  
  53.       
  54.     return 0;  
  55. }  
#include <stdio.h>
#include <windows.h>
//这里的行可以自由写,这样就不受限制,想做出什么样的效果都可以。
int array[][10] =  {
0x03,0x00,0x00,0x00,0x00,//第一列
0x00,0x02,0x00,0x00,0x00,

0x0C,0x00,0x00,0x00,0x00,//第二列
0x00,0x04,0x00,0x00,0x00,

0x10,0x00,0x00,0x00,0x00,//第三列
0x00,0x08,0x00,0x00,0x00,

0x60,0x00,0x00,0x00,0x00,//第四列
0x00,0x10,0x00,0x00,0x00,

0x80,0x01,0x00,0x00,0x00,//第五列
0x00,0x20,0x00,0x00,0x00,

0xAA,0x55,0x00,0x00,0xC0,//end
0x00,0x00,0x00,0x00,0x00,

};

void to_Q112_cmd_designator_LED(int *array)
{
int i;
for(i = 0; i < 10; i++)
{
printf(" %3d “, *(array+i));
}
printf(”\n");
}

void delay_500ms(void)
{
Sleep(500);
}

int main(void)
{
int i,j;
int tick;
int count = 0;
while(array[count][0] != 0xAA || array[count][1] != 0x55)//如果当数组第count行第0列等于0xAA,或者第count行第1列等于0x55时,那么就退出,否则就循环执行遍历数据
{
to_Q112_cmd_designator_LED((int )(&array[0][0]+count10) );//以首元素每次向后偏移10个字节
delay_500ms();

	count++;
}

return 0;

}运行结果:

   3    0    0    0    0    0    2    0    0    0
  12    0    0    0    0    0    4    0    0    0
  16    0    0    0    0    0    8    0    0    0
  96    0    0    0    0    0   16    0    0    0
 128    1    0    0    0    0   32    0    0    0


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值