⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fengcpp1.cpp

📁 驱动LCD,在avr mega48(价格6元人民币) 测试通过,虽然小,可是 C++ 的,
💻 CPP
字号:
//fengcpp1.cpp : source file for the fengcpp1 project
//

#include "fengcpp1.h"
#include <lcd.h>

/////////////////////////////////////////////////////////////////////////////
//fengcpp1

class person
{
public:
	void Run(int intNewSpeed);
	void Step();
	void Stop();
	int GetCurrentSpeed();
	void (*pReach)(int);
	int chName;
private:
	int intSpeed;
	int intHowLong;
};

void person::Run(int intNewSpeed)
{
	if (intNewSpeed < 36)
		intSpeed=intNewSpeed;
	else
		intSpeed=36;
}
void person::Stop()
{
}
int person::GetCurrentSpeed()
{
	return intSpeed;
}
void person::Step()
{
	intHowLong += intSpeed;
	if (intHowLong>1000 )
		(*pReach)(chName);
}
static void io_init(void)
{
	//{{WIZARD_MAP(General)
	//}}WIZARD_MAP(General)

	//{{WIZARD_MAP(I/O Ports)
	// PortB
	PORTB = 0x0;
	DDRB = 0x0;
	// PortC
	PORTC = 0x0;
	DDRC = 0x7f;
	// PortD
	PORTD = 0x0;
	DDRD = 0x0;
	//}}WIZARD_MAP(I/O Ports)

	//{{WIZARD_MAP(Watchdog)
	// Watchdog Disabled
	wdt_disable();
	//}}WIZARD_MAP(Watchdog)

	//{{WIZARD_MAP(Analog Comparator)
	// Analog Comparator Disabled
	ACSR = 0x80;
	//}}WIZARD_MAP(Analog Comparator)
}

static void reset_checking(void)
{
	if (MCUCSR & BV(PORF))
	{	// Power-on Reset
		
	}
	else if (MCUCSR & BV(EXTRF))
	{	// External Reset
		
	}
	else if (MCUCSR & BV(WDRF))
	{	// Watchdog Reset
		
	}
	MCUCSR &= 0xE0;
}

void AfterReach(int name)
{
// 	cout << "" <<
	int xx;
	xx=name;
	if (xx==2)
		xx=0;
	else if (xx==1)
		xx=9;
// 	nop;
	xx=0;
}

int main(void)
{
	unsigned i,k;
	person   feng;
	person   sun;
	feng.pReach = AfterReach;
	sun.pReach=AfterReach;
	
	feng.chName=1;
	sun.chName=2;
	// Reset source checking
	reset_checking();
	//{{WIZARD_MAP(Initialization)
	io_init();
// 	lcd_init(16, 2, &PORTB);	// LCD Using PORTB
	//}}WIZARD_MAP(Initialization)
	// TODO: Add extra initialization here
	
	//{{WIZARD_MAP(Global interrupt)
	//}}WIZARD_MAP(Global interrupt)
	while(1)
	{
		// TODO: Add your code here
		for (i=0;i<10;i++)
		{
			feng.Step();
			sun.Step();
		}
		k++;
		sun.Run(k);
		feng.Run(k/2);
//		sun.Run (k);
		feng.GetCurrentSpeed();

		
// 		if((k % 2) == 1)
// 			PORTC=0;
// 		else
// 			PORTC=0xff;
// 		
// 		lcd_putchar(k%256);
// 		if ((k % 15 )==0)
// 			lcd_clear();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -