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

📄 stcmcu.c

📁 使用STC12C5410AD单片机作为开发系统实现简易闹钟、秒表、打铃小系统程序。包含实时时钟芯片HT1380控制
💻 C
字号:
#include <absacc.h>
#include "STC12C5410AD.H"
#include "ht1380.h"
#include "a93c46.h"
#include "ADConvert.h"

uchar pcurTim[7];
uchar pDate[]={0x08,0x08,0x0d,0x1b,0x08,0x03,0x08};
//格式为: 秒00-59, 分00-59, 时01-12/00-23, 日01-31, 月01-12, 星期01-07, 年00-99
//写入的时间为08年8月27日星期三13时8时8分
uint ADC_res; //AD转换结果
uchar data AD_channel_result[5]; 	//所选通道A/D转换结果。存放转换为字符串后的值

/*串口相关寄存器初始化*/
void Init_Com(void)
{
	TMOD = 0x20; //定时器1模式2
	PCON = 0x00; //
	SCON = 0x50; //串口为方式1 UART
	TH1 = 0xFd;
	TL1 = 0xFd; //波特率9600
	TR1 = 1;
	REN = 1;
	ES = 1;
	EA = 1;
}
/*串口接收中断服务程序*/
void ComInt() interrupt 4
{
	unsigned char dat;
	ES = 0;
	RI = 0;
	dat = SBUF;
	SBUF = dat;
	do
	{;					//Reserve
	}while( TI == 0 );
	TI = 0;
	ES = 1;
}

void uint_to_str(uint data_res,uchar *str_res)
{
   	/*转换成可由串口显示的字符*/
	str_res[0] = data_res/1000+0x30;	   	//千位
	str_res[1] = (data_res%1000)/100+0x30;	//百位
	str_res[2] = (data_res%100)/10+0x30;  	//十位
	str_res[3] = data_res%10+0x30;		   	//个位

	/*串口监视*/
	// send_char_com(ADC_DATA);      //发送转换 的 到的 值,这里只是 高8位,值的转换需要考虑
	// send_char_com(ADC_LOW2);      //发送转换 的 到的 值,这里只是 低2位,值的转换需要考虑
	
	//send_string_com(AD_channel_result[channel],4);
}

/*主程序*/
void main()
{
	/*调用HT1380设置、读取时间*/
	v_Set1381(pDate);	//设定1380时间
	v_Get1381(pcurTim);	//读取1380时间

	/*调用93C46写入数据*/
	WriteChar(0x12,0x45);

	/*调用STC内部AD进行AD转换,得到10位结果*/
	ADC_res = startADC(0);
	uint_to_str(ADC_res,AD_channel_result);

	Init_Com();
	while(1)
	{;					//Reserve
	}
}

⌨️ 快捷键说明

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