芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密

飞芯科技提供芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密逆向服务

STC15W4K32S4单片机ADC读取 串口收发单片机解密

单片机解密单片机源程序如下:

  1. /*---------------------------------------------------------------------*/
  2. /* --- STC MCU Limited ------------------------------------------------*/
  3. /* --- STC15F4K60S4 系列 定时器1用作串口1的波特率发生器举例------------*/
  4. /* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序        */
  5. /* 如果要在文章中应用此代码,请在文章中注明使用了STC的资料及程序        */
  6. /*---------------------------------------------------------------------*/

  7. //本示例在Keil开发环境下请选择Intel的8058芯片型号进行编译
  8. //若无特别说明,工作频率一般为11.0592MHz

  9. #include        "STC15Fxxxx.H"
  10. //#include "reg51.h"
  11. #include <stdio.h>

  12. typedef unsigned char BYTE;
  13. typedef unsigned int WORD;
  14. //typedef unsigned int u16;  //对数据类型进行声明定义
  15. //typedef unsigned char u8;

  16. #define FOSC 11059200L          //系统频率
  17. #define BAUD 115200             //串口波特率

  18. #define NONE_PARITY     0       //无校验
  19. #define ODD_PARITY      1       //奇校验
  20. #define EVEN_PARITY     2       //偶校验
  21. #define MARK_PARITY     3       //标记校验
  22. #define SPACE_PARITY    4       //空白校验

  23. #define PARITYBIT NONE_PARITY   //定义校验位
  24. /* STC15Fxxxx.H中已定义
  25. //sfr P0M1 = 0x93;
  26. //sfr P0M0 = 0x94;
  27. //sfr P1M1 = 0x91;
  28. //sfr P1M0 = 0x92;
  29. //sfr P2M1 = 0x95;
  30. //sfr P2M0 = 0x96;
  31. //sfr P3M1 = 0xb1;
  32. //sfr P3M0 = 0xb2;
  33. //sfr P4M1 = 0xb3;
  34. //sfr P4M0 = 0xb4;
  35. //sfr P5M1 = 0xC9;
  36. //sfr P5M0 = 0xCA;
  37. //sfr P6M1 = 0xCB;
  38. //sfr P6M0 = 0xCC;
  39. //sfr P7M1 = 0xE1;
  40. //sfr P7M0 = 0xE2;

  41. //sfr AUXR  = 0x8e;               //辅助寄存器

  42. //sfr P_SW1   = 0xA2;             //外设功能切换寄存器1
  43. */
  44. #define S1_S0 0x40              //P_SW1.6
  45. #define S1_S1 0x80              //P_SW1.7

  46. #define ADC_POWER   0x80            //ADC电源控制位
  47. #define ADC_FLAG    0x10            //ADC完成标志
  48. #define ADC_START   0x08            //ADC起始控制位
  49. #define ADC_SPEEDLL 0x00            //540个时钟
  50. #define ADC_SPEEDL  0x20            //360个时钟
  51. #define ADC_SPEEDH  0x40            //180个时钟
  52. #define ADC_SPEEDHH 0x60            //90个时钟

  53. //sbit P22 = P2^2;
  54. unsigned int ch;a,b;
  55. unsigned int dd=0;
  56. unsigned int cc=0;
  57. unsigned int cc0=0;
  58. unsigned int cc1=0;
  59. unsigned int cc00=0;
  60. unsigned int cc01=0;
  61. unsigned int cc10=0;
  62. unsigned int cc11=0;
  63. unsigned int time0count0 = 0 ;
  64. unsigned int time0count1 = 0 ;
  65. unsigned int time0count = 3000 ;
  66. bit busy;
  67. char receivechar = 0;
  68. int receive_count = 0;
  69. int received = 0;
  70. WORD receivestr[10];

  71. void InitUart();
  72. void InitADC();
  73. void Timer0Init();
  74. void SendData(BYTE dat);
  75. void SendString(char *s);
  76. void serial_put_uint(unsigned int number);
  77. void Delay(WORD n);
  78. //void ShowResult(BYTE ch);
  79. unsigned int GetADCResultint(BYTE ch);
  80. void main()
  81. {
  82.         int initreceivestrcount=0;
  83.         unsigned int tt0=0,tt1=0;
  84. //                unsigned int d1,d2,d3,i;
  85.         unsigned int i=0;
  86.         if (i == 0 )                //初始化tt0 tt1 P0 -P7 数据
  87.         {
  88.                 /*
  89.                 例如将P1M0=0X60和P1M1=0X00译成bai二进制代码是
  90.                 P1M0=0110 0000,duP1M1=0000 0000.
  91.                 按照I/O口工作模式设置zhi规定
  92.                 都为0时为准双向口(dao传统8051单片机zhuanI/O口模式)
  93.                 为0,1时为推挽(shu强上拉输出),
  94.                 为1,0时为高阻(仅输入),
  95.                 为1,1时为开漏(内部上拉断开,须外加上拉电阻)
  96.                 你选择的是P1M0和P1M1所以针对的是P1口的操作,
  97.                 将两个二进制代码一位位的比较可知:P1.0~P1.4及P1.7都为0,
  98.                 故这些I/O口设置的是标准状态;P1.5和P1.6为高阻态
  99.                 (P1M0上的第六位和第七位都为1,P1M1上的第六位和第七位都是0。1,0时为高阻)
  100.                 */
  101.                 tt0=16640;
  102.                 tt1=tt0/256;
  103.                 P0M0 = 0x00;
  104.                 P0M1 = 0x00;
  105.                 P1M0 = 0x00;
  106.                 P1M1 = 0x03;
  107.                 P2M0 = 0x00;
  108.                 P2M1 = 0x00;
  109.                 P3M0 = 0x00;
  110.                 P3M1 = 0x00;
  111.                 P4M0 = 0x00;
  112.                 P4M1 = 0x00;
  113.                 P5M0 = 0x00;
  114.                 P5M1 = 0x00;
  115.                 P6M0 = 0x00;
  116.                 P6M1 = 0x00;
  117.                 P7M0 = 0x00;
  118.                 P7M1 = 0x00;
  119.         }
  120.         InitUart();                     //初始化串口
  121.         //printf ("20200102 第一次调试  a  1 取左字节   a %d A/256=A %d   C51\n" , tt0,tt1 ); /* ?? "Hello C51 " */
  122.         SendString("20200102 第二次调试 \r\n");
  123.         initreceivestrcount=0;
  124.         while (initreceivestrcount<10)                //初始化 receivestr
  125.         {
  126.                 receivestr[initreceivestrcount]=0;
  127.                 initreceivestrcount = initreceivestrcount + 1 ;
  128.         }
  129.         //printf ("Hello");  //printf 不能使用 编译通过 不能仿真运行
  130.         InitADC();                      //初始化ADC
  131.         Timer0Init();  //定时器0初始化
  132.         /* 除法测试
  133.                 //printf ("Hello  ADC 第y次调试 a  1 加代码a %d A/256=A %d   C51\n" , tt0,tt1 );  
  134. //                sprintf(str," receive %d \r\n",receivechar);
  135. //                SendString(str);
  136. //                sprintf(str," d1 %d a \r\n",tt0);
  137. //                SendString(str);
  138. //                sprintf(str,"  d2 %d  a \r\n",tt1);
  139. //                SendString(str);
  140. //                sprintf(str,"  d3 %d a \r\n",d3);
  141. //                SendString(str);
  142.         */
  143.     SendString("c STC15W4kS32\r\n Uart Test !\r\n");
  144.     while(1)
  145.                 {

  146.                         if (received == 1)                // 在串口接收预定义字符后回送  20210103 增加控制定时显示功能
  147.                         {
  148.                                 /*  除法测试及sprintf
  149. //                                SendString("\r\n");
  150. //                                d1 = receivechar;
  151. //                                d2 = d1 ;
  152. //                                d3=d2*256;
  153. //                                d3=d1-d3;
  154. //                                sprintf(str," receive %d a\r\n",receivechar);
  155. //                                SendString(str);
  156. //                                sprintf(str," d1 %d b \r\n",d1);
  157. //                                SendString(str);
  158. //                                sprintf(str,"  d2 %d  c \r\n",d2);
  159. //                                SendString(str);
  160. //                                sprintf(str,"  d3 %d d \r\n",d3);
  161. //                                SendString(str);
  162. //                                SendString(receivestr);receivechar
  163.                                 */
  164.                                 serial_put_uint(receivechar);
  165.                                 SendString(" start ");
  166.                                 //serial_put_uint(11);
  167.                                 for (i=0;i<receive_count;i++)
  168.                                 {
  169.                                         SendData(receivestr[i]);
  170.                                 }
  171.                                 SendString(" COUNT= ");
  172.                                 serial_put_uint(receive_count);
  173.                                 receive_count = 0 ;
  174.                                 if (receivestr[1] == 65 )
  175.                                 {
  176.                                         time0count = ( receivestr[2] - 48 ) * 1000 ;
  177.                                         SendString(" \r\n  串口设定 time0   ");                                                                                                
  178.                                         serial_put_uint(time0count/1000);
  179.                                         SendString(" 秒定时  ");        
  180.                                 }                                       
  181.                                 SendString(" \r\n");
  182.                                 received = 0 ;
  183.                         }
  184.                         if (time0count0 != time0count1)                         // 串口设定的秒定时
  185.                         {
  186.                                 SendString(" time0   ");                                                                                                
  187.                                 serial_put_uint(time0count/1000);
  188.                                 SendString(" 秒定时 执行 ");                                                                                                
  189.                                 serial_put_uint(time0count0);
  190.                                 SendString(" \r\n ");               
  191.                                 time0count1 = time0count0;
  192.                         }                                
  193.                         b=b+1;
  194.                         dd=0;
  195.                         cc00 = GetADCResultint(dd);                 //读取ADC 0 P1.0 数据
  196.                         if (cc01 != cc00)                         // ADC 0 P1.0 数据变化发送串口
  197.                         {
  198.                                 SendString(" ADC ");                                                                                                
  199. //                                serial_put_uint(b);
  200.                                 SendString(" ch ");                                                                                                
  201.                                 serial_put_uint(dd);
  202.                                 SendString(" new ");                                                                                                
  203.                                 serial_put_uint(cc00);
  204.                                 SendString("  old ");                                                                                                
  205.                                 serial_put_uint(cc01);
  206.                                 SendString(" end \r\n");                                                                                                
  207.                                 //printf ("  ADC %d  ch %d :0x  %x 0d %d  \n", b,dd,cc00,cc01 );
  208.                                 cc01 = cc00;
  209.                         }
  210.                         dd=1;
  211.                         cc10 = GetADCResultint(dd);                        //读取ADC 1 P1.1 数据
  212.                         if (cc11 != cc10)                                // ADC 1 P1.1 数据变化发送串口
  213.                         {
  214.                                 SendString(" ADC ");                                                                                                
  215. //                                serial_put_uint(b);
  216.                                 SendString(" ch ");                                                                                                
  217.                                 serial_put_uint(dd);
  218.                                 SendString(" new ");                                                                                                
  219.                                 serial_put_uint(cc10);
  220.                                 SendString("  old ");                                                                                                
  221.                                 serial_put_uint(cc11);
  222.                                 SendString(" end \r\n");                                                                                                
  223.                                 //printf ("  ADC  %d ch %d :0x  %x 0d00 %d  \n", b,dd,cc10,cc11 );
  224.                                 cc11=cc10;
  225.                         }
  226.                         dd=0;
  227.                         if  (b>10000) b=0;

  228.                 }



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.taihedz.cn
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信