📄 da.txt
字号:
*文件:dac7512_main.c
*环境:编译为KEIL 802
*硬件:ATmage16L芯片
*功能:第1行显示:jdzczz.bokee.com
* 第2行显示:2008
* 第4行显示:The reslt of DA is:
* 第5-行显示:输出的电压值
*晶振频率为 8MHz
*DAC7512 D/A转换 串口显示
***************************************************************/
/************************包含库函数****************************/
#include <iom16v.h>
#include <macros.h>
#include <stdio.h>
#include "Uart.h"
/************************相关定义******************************/
const char buffer[24]="jdzczz.bokee.com";
const char buffer1[24]="The reslt of DA is:";
char Data[4]={2|0x30,0|0x30,0|0x30,8|0x30}; //显示初始值:2 0 0 8
extern unsigned int K;
/***************************************************************
*功能说明:端口初始化
***************************************************************/
void port_init()
{
PORTA=0Xff;
DDRA=0Xff;
PORTC=0Xff;
DDRC=0Xff;
}
/***************************************************************
*功能说明:出错提示
***************************************************************/
void error() //错误时发送2008
{
Uart_Send_data(Data,4);
}
/***************************************************************
*功能说明:数据处理
***************************************************************/
void Process(unsigned int i,char *p)
{
i=i*1.263096;
p[0]=(i/1000)|0x30;
i=i%1000;
p[1]=(i/100)|0x30;
i=i%100;
p[2]=(i/10)|0x30;
i=i%10;
p[3]=i|0x30;
}
/***************************************************************
*功能说明:主函数
***************************************************************/
void main(void)
{
char i=0;
port_init(); //初始化端口
Uart_Init(9600); //设置波特率为9600
Uart_Send_string(buffer);
Uart_Send_char(0x0a); //发送一个换行
Uart_Send_data(Data,4);
Uart_Send_string(buffer1);
Uart_Send_char('\n');
SEI();
for(i=0;i<5;i )
{
Process(K,Data); //读取接收到的数据
Uart_Send_data(Data,4);
}
while(1)
{
SPI_MasterInit(); //主控发送
SPI_MasterTransmit(0x0F); //DA数据输入
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -