收藏0 举报
for(i=0; i<65535; i++) //全部语句可以运行8988次 { x=test(37); //注释这条可以运行9580次 out=x; if(x>47) x=57; else x=67; //注释这条可以运行9998次 out=x; x<<=1; //注释这条可以运行9248次 out=x; x>>=1; //注释这条可以运行9248次 out=x; x|=1; //注释这条可以运行9142次 out=x; x&=1; //注释这条可以运行9142次 out=x; x=~x; //注释这条可以运行9142次 out=x; x=x^1; //注释这条可以运行9142次 out=x; x+=1; //注释这条可以运行9090次 out=x; x-=1; //注释这条可以运行9090次 out=x; x*=3; //注释这条可以运行9523次 out=x; x/=3; //注释这条可以运行9523次 out=x; x%=3; //注释这条可以运行9638次 out=x; } while(1);
panxiaoyi 发表于 2021-4-21 16:59 第3行是简单的函数调用,out=x;是对寄存器赋值,全部都是 unsigned char 变量,怎么PIC就这么慢? ...
您需要 登录 才可以下载或查看,没有账号?注册
// #define ALLOCATE_EXTERN #include "HC89F0541.h" #include "BIT.h" #include "FONT0805.h" #include "DELAY_LONG.h" #include "MCUIIC.h" #include "SH1106.h" #define out P1 unsigned int i, n; unsigned char x, a; unsigned char test(unsigned char dat) { unsigned char y; y=dat; return y; } void TIMER3_ISR(void) interrupt 10 { n++; P2_7 =1; //LED亮 WDTC |= 0x10; //看门狗清零 OLED_gotoxy(71,3); //显示时间 OLED_show(n); P2_7 =0; if(a) //显示:程序在1600K个CPU时钟里运行for()语句的次数 { a=0; OLED_gotoxy(35,3); OLED_show(i); } } void main(void) { CLKSWR = 0x51; //选择内部高频RC为系统时钟,内部高频RC2分频,Fosc=16MHz CLKDIV = 0x01; //CPU时钟Fcpu=Fosc/分频值,比如CLKDIV=0x01,则CPU=16MHz P2M7 = 0xC2; //P27设置为推挽输出驱动LED IIC_init(); OLED_init(); OLED_clear(); OLED_gotoxy(14,1); OLED_string("HC8051 ==> SH1106"); OLED_gotoxy(11,5); OLED_string("21IC.COM PANXIAOYI"); EA = 1; //打开总中断 T3CON=0; T3CON B5H; T3CON B4H; //计数时钟=Fosc/256分频 TH3 = 0xE7; TL3 = 0x96; //消耗时钟=(65536-0xE796)*256分频=1600K,即中断时间是100ms ET3 = 1; //打开T3中断 T3CON B2H; //启动定时器 a=1; i=1; n=0; while(1) { for(i=0; i<65535; i++) //全部语句可以运行8988次 { x=test(37); //注释这条可以运行9580次 out=x; if(x>47) x=57; else x=67; //注释这条可以运行9998次 out=x; x<<=1; //注释这条可以运行9248次 out=x; x>>=1; //注释这条可以运行9248次 out=x; x|=1; //注释这条可以运行9142次 out=x; x&=1; //注释这条可以运行9142次 out=x; x=~x; //注释这条可以运行9142次 out=x; x=x^1; //注释这条可以运行9142次 out=x; x+=1; //注释这条可以运行9090次 out=x; x-=1; //注释这条可以运行9090次 out=x; x*=3; //注释这条可以运行9523次 out=x; x/=3; //注释这条可以运行9523次 out=x; x%=3; //注释这条可以运行9638次 out=x; } while(1); } }
// #include "Configuration.h" #include <xc.h> #include "BIT.h" #include "DELAY_LONG.h" #include "FONT0805.h" #include "MCUIIC.h" #include "SH1106.h" #define out LATA unsigned int i, n; unsigned char x, a; unsigned char test(unsigned char dat) { unsigned char y; y=dat; return y; } void __interrupt() isr(void) { TMR0IF=0; //清零中断位 n++; OLED_gotoxy(71,3); //显示时间 OLED_show(n); if(a) //显示:程序在1600K个CPU时钟里运行for()语句的次数 { a=0; OLED_gotoxy(35,3); OLED_show(i); } } void main(void) { IIC_init(); OLED_init(); OLED_clear(); OLED_gotoxy(11,1); OLED_string("PIC18F26K83>SH1106"); OLED_gotoxy(11,5); OLED_string("21IC.COM PANXIAOYI"); GIEH=1; //全局中断允许位 GIEL=1; //外设中断允许位 IPEN=0; //禁止中断优先级 T0CON1=64+13; //时钟源=Fosc/4,8192预分频 TMR0H=195; //8位计时的周期值 TMR0IE=1; //中断使能,速度=16M/(8192*195)=10次/秒 T0CON0|=0x80; //TMR0 使能位 a=1; i=1; n=0; while(1) //下面这些是 51 单片机的数据 { for(i=0; i<65535; i++) //全部语句可以运行8988次 { x=test(37); //注释这条可以运行9580次 out=x; if(x>47) x=57; else x=67; //注释这条可以运行9998次 out=x; x<<=1; //注释这条可以运行9248次 out=x; x>>=1; //注释这条可以运行9248次 out=x; x|=1; //注释这条可以运行9142次 out=x; x&=1; //注释这条可以运行9142次 out=x; x=~x; //注释这条可以运行9142次 out=x; x=x^1; //注释这条可以运行9142次 out=x; x+=1; //注释这条可以运行9090次 out=x; x-=1; //注释这条可以运行9090次 out=x; x*=3; //注释这条可以运行9523次 out=x; x/=3; //注释这条可以运行9523次 out=x; x%=3; //注释这条可以运行9638次 out=x; } while(1); } }
panxiaoyi 发表于 2021-4-23 00:56 请问是不是要加上 OSCFRQ=8; 这个语句?改变这个值的确会改变LED的闪烁速度,但是 for() 运行次数还是不变 ...
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
发帖类勋章
人才类勋章
时间类勋章
102
227
0
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号