|
| P0口要接上拉電阻 |
|
本帖最后由 dy212300 于 2019-12-17 16:09 編輯 是P0=b |
| 燒的以前的程序?? |
本帖最后由 wulin 于 2019-12-17 10:16 編輯 新人求指導啊1 發表于 2019-12-16 17:15 程序基本可行,但寫得有點啰嗦,甚至不合理。仿真異常是圖畫錯,必須要在LED串接300Ω~1K左右限流電阻,否則實際電路IO口有燒毀的風險。程序可以簡化為:
|
| crol是循環左移,延時太短,程序中再加3個delay(250);試試 |
|
程序如下: #include <reg51.h> #include <stdio.h> #include <intrins.h> sbit P0_0 = P0^0; sbit P0_1 = P0^1; sbit P0_2 = P0^2; sbit P0_3 = P0^3; sbit P0_4 = P0^4; sbit P0_5 = P0^5; sbit P0_6 = P0^6; sbit P0_7 = P0^7; void delay(unsigned char a) { unsigned char i; while(--a!=0) { for(i=0;i<125;i++); } } void main(void) { unsigned char b; unsigned char i; while(1) { b=0x7f; for(i=0;i<8;i++) { P0=_crol_(b,1); b=P0; delay(250); } } } |