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

📄 main.c

📁 可以通过向电子指南针模组发送不同的命令字
💻 C
字号:
//======================================================
//  The information contained herein is the exclusive property of
//  Sunnnorth Technology Co. And shall not be distributed, reproduced,
//  or disclosed in whole in part without prior written permission.
//  (C) COPYRIGHT 2003  SUNNORTH TECHNOLOGY CO.
//  ALL RIGHTS RESERVED
//  The entire notice above must be reproduced on all authorized copies.
//========================================================

//========================================================
//  工程名称:	compass_driver
//  功能描述:	利用指南针模组得到角度值
//  涉及的库:	CMacro1016.lib
//            	clib.lib
//  组成文件:	main.c
//				SPLC501User.c  SPLC501Driver_IO.asm
//				PNI_Driver.asm
//				PNI_Driver.h
//	硬件连接:	
//              IOA8-15接液晶显示模块DB0-DB7
//              IOB4接液晶显示模块AO
//              IOB5接液晶显示模块的R/W
//              IOB6接液晶显示模块的EP
//				IOB8~15接指南针模块
//	维护记录:	2005-12-12 v1.0
//========================================================
//======================================================================
//	文件名称:	main.c
//	功能描述:  通过液晶屏显示从电子指南针得到的X轴、Y轴的测量值,和计算的角度值
//	维护记录:	2007-12-30	v1.0
//======================================================================
#include "./PNI_Driver/PNI_Driver.h"
#include "./SPLC501_Driver/SPLC501User.h"
#include "spce061a.h"
#include "stdio.h"
#include "math.h"
#define PI	3.1415926
int main()
{
	//add your code here
	unsigned int Show[9];
	int xValue, yValue=150;
	float ratio, angle;

	F_PNI_11096_Init();									// 初始化PNI11096
	LCD501_Init(0x00);

	while(1)
	{
		xValue = F_PNI_11096_Read(0xE9);				// x轴方向测量值
		sprintf(Show, "%05d", xValue);
		LCD501_PutString(0, 0, Show);

		yValue = F_PNI_11096_Read(0xEA);				// y轴方向测量值
		sprintf(Show, "%05d", yValue);
		LCD501_PutString(0, 20, Show);

		if((xValue == 0) && (yValue > 0))				// 正北方向
		{
			angle = 0;
			sprintf(Show, "%f", angle);
			LCD501_PutString(0, 40, Show);
		}
		else if((xValue == 0) && (yValue < 0))			// 正南方向
		{
			angle = 180;
			sprintf(Show, "%f", angle);
			LCD501_PutString(0, 40, Show);
		}
		else
		{
			ratio = (float)yValue / (float)xValue;
			angle = atanf(ratio);						// 利用反正切得到角度值
			angle = 180 * angle / PI;
			

			sprintf(Show, "%f", angle);
			LCD501_PutString(0, 40, Show);
		}

		*P_Watchdog_Clear = 0x0001;
	}
	return 0;
}

⌨️ 快捷键说明

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