设为首页收藏本站淘宝杂货铺

从F到0 - From F to 0

 找回密码
 注册已关闭
搜索
查看: 1738|回复: 0
收起左侧

C51/STC系列单片机 晶振超频RAM内存读写出错/程序跑飞 抗干扰能力测试程序 Keil4编译

[复制链接]
发表于 2020-7-15 22:51:52 | 显示全部楼层 |阅读模式
1.png

  1. //电压越低且晶振频率越高,出错概率越高
  2. #include "reg51.h"
  3. #include "intrins.h"
  4. unsigned char pc=0;
  5. unsigned char byte=0;
  6. unsigned char ram[100];
  7. sfr AUXR   = 0x8E;
  8. sbit LED=P3^3;                //正常状态此灯不断闪烁
  9. sbit ERR=P3^4;                //程序运行出错,则点亮此灯
  10. sbit OK=P3^5;                //运行正确,则点亮此灯
  11. void Delay1000ms()                //@35MHz
  12. {
  13.         unsigned char i, j, k;

  14.         i = 133;
  15.         j = 255;
  16.         k = 40;
  17.         do
  18.         {
  19.                 do
  20.                 {
  21.                         while (--k);
  22.                 } while (--j);
  23.         } while (--i);
  24. }


  25. void InitTimer0(){        //35Mhz@1mS
  26.     TMOD = 0x01;
  27.     TH0 = 0x77;
  28.     TL0 = 0x48;
  29.     EA = 1;
  30.     ET0 = 1;
  31.     TR0 = 1;
  32. }
  33. void main(){
  34. AUXR |= 0x80;        //上电全部点亮1秒后熄灭
  35. OK = 0;ERR = 0;LED = 0;
  36. Delay1000ms();
  37. OK = 1;ERR = 1;LED = 1;
  38. InitTimer0();
  39.         while(1){
  40.                 for(pc=0;pc<100;pc++){
  41.                 ram[pc]=byte;
  42.                         if(ram[pc] != byte){
  43.                         TR0 = 0;
  44.                         OK = 1;
  45.                         LED = 1;
  46.                         ERR = 0;
  47.                         while(1);
  48.                         }
  49.                 byte++;
  50.                 }
  51.        
  52.         OK = 0;
  53.         ERR = 1;
  54. }

  55. }
  56. unsigned int ms=0;
  57. void Timer0Interrupt() interrupt 1{
  58.     TH0 = 0x77;
  59.     TL0 = 0x48;
  60.         if(++ms >= 500){
  61.         ms=0;
  62.         LED = ~LED;
  63.         }
  64. }
复制代码

相关帖子

您需要登录后才可以回帖 登录 | 注册已关闭

本版积分规则

QQ|手机版|Archiver|从F到0 ( 蒙ICP备17002595号-1 )
蒙公网安备15010402000325号

腾讯云安全认证

GMT+8, 2024-4-16 15:03 , Processed in 0.448026 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表