天天看點

C言語指針的複雜示例

#include <reg52.h> sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADDR3 = P1^3; sbit ENLED = P1^4; void ShiftLeft(unsigned char *p); void main(){ unsigned int i; unsigned char buf = 0x01; ENLED = 0; //使能選擇自力 LED ADDR3 = 1; ADDR2 = 1; ADDR1 = 1; ADDR0 = 0; while (1){ P0 = ~buf; //緩沖值取反送到 P0 口 for (i=0; i<20000; i++); //延時 ShiftLeft(&buf); //緩沖值左移一位 if (buf == 0){ //如移位後為 0 則重賦初值 buf = 0x01; } } } /* 将指針變量 p 指向的位元組左移一位 */ void ShiftLeft(unsigned char *p){ *p = *p << 1; //應用指針變量可以向函數外輸入運算後果 }      

繼續閱讀