user-0 提问: 初学C语言单片机 求大佬指点一下

回复:
user: user-1
content: 引用 1 楼 weixin_45631157的回复:这是完整的程序 #include <reg52.h> typedef unsigned int u16; typedef unsigned char u8; sbit right1 = P0^0; sbit right2 = P0^1; sbit left1 = P0^2; sbit left2 = P0^3; void delay(u16 i) 	{ 		while(i--); 	} 	void left() 		{ 			right1 = 0; 			right2 = 1; 			left1 = 0; 			left2 = 0; 		} void left_back() 	{ 		right1 = 1; 		right2 = 0; 		left1 = 0; 		left2 = 0; } void right() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 1; 		left2 = 0; 	} void right_back() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 0; 		left2 = 1; 	} void run() 	{	 		right1 = 0; 		right2 = 1; 		left1 = 1; 		left2 = 0; 	} void dig_left() 	{  		right1 = 1; 		right2 = 0; 		left1 = 1; 		left2 = 0; 	} void dig_right() 	{ 		right1 = 0; 		right2 = 1; 		left1 = 0; 		left2 = 1; 	} void run_back() 	{ 		right1 = 1; 		right2 = 0; 		left1 = 0; 		left2 = 1;	 	} void stop() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 0; 		left2 = 0; 	} void main() 	{ 		while(1) 		{ 			run(); 			delay(10000000); 			dig_left(); 			delay(10000000); 			dig_right(); 			delay(10000000); 			run_back(); 			delay(10000000); 			stop(); 			delay(10000000); 		} 	} 看你u16是int型，不清楚你的系统情况，u16指的是16位吗？

user: user-1
content: 引用 1 楼 weixin_45631157的回复:这是完整的程序 #include <reg52.h> typedef unsigned int u16; typedef unsigned char u8; sbit right1 = P0^0; sbit right2 = P0^1; sbit left1 = P0^2; sbit left2 = P0^3; void delay(u16 i) 	{ 		while(i--); 	} 	void left() 		{ 			right1 = 0; 			right2 = 1; 			left1 = 0; 			left2 = 0; 		} void left_back() 	{ 		right1 = 1; 		right2 = 0; 		left1 = 0; 		left2 = 0; } void right() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 1; 		left2 = 0; 	} void right_back() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 0; 		left2 = 1; 	} void run() 	{	 		right1 = 0; 		right2 = 1; 		left1 = 1; 		left2 = 0; 	} void dig_left() 	{  		right1 = 1; 		right2 = 0; 		left1 = 1; 		left2 = 0; 	} void dig_right() 	{ 		right1 = 0; 		right2 = 1; 		left1 = 0; 		left2 = 1; 	} void run_back() 	{ 		right1 = 1; 		right2 = 0; 		left1 = 0; 		left2 = 1;	 	} void stop() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 0; 		left2 = 0; 	} void main() 	{ 		while(1) 		{ 			run(); 			delay(10000000); 			dig_left(); 			delay(10000000); 			dig_right(); 			delay(10000000); 			run_back(); 			delay(10000000); 			stop(); 			delay(10000000); 		} 	} u16的最大值是65536，你给delay传递的值太大了

user: user-2
content: 错误在那里，贴错误出来看看

user: user-0
content: 这是完整的程序 #include <reg52.h> typedef unsigned int u16; typedef unsigned char u8; sbit right1 = P0^0; sbit right2 = P0^1; sbit left1 = P0^2; sbit left2 = P0^3; void delay(u16 i) 	{ 		while(i--); 	} 	void left() 		{ 			right1 = 0; 			right2 = 1; 			left1 = 0; 			left2 = 0; 		} void left_back() 	{ 		right1 = 1; 		right2 = 0; 		left1 = 0; 		left2 = 0; } void right() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 1; 		left2 = 0; 	} void right_back() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 0; 		left2 = 1; 	} void run() 	{	 		right1 = 0; 		right2 = 1; 		left1 = 1; 		left2 = 0; 	} void dig_left() 	{  		right1 = 1; 		right2 = 0; 		left1 = 1; 		left2 = 0; 	} void dig_right() 	{ 		right1 = 0; 		right2 = 1; 		left1 = 0; 		left2 = 1; 	} void run_back() 	{ 		right1 = 1; 		right2 = 0; 		left1 = 0; 		left2 = 1;	 	} void stop() 	{ 		right1 = 0; 		right2 = 0; 		left1 = 0; 		left2 = 0; 	} void main() 	{ 		while(1) 		{ 			run(); 			delay(10000000); 			dig_left(); 			delay(10000000); 			dig_right(); 			delay(10000000); 			run_back(); 			delay(10000000); 			stop(); 			delay(10000000); 		} 	}