电子设计指导 51AVR PIC ARM单片机C程序 Proteus仿真电路图
AVR系列单片机C程序代写及protues的仿真图。
PIC系列单片机C程序代写及protues的仿真图。
51、52系列单片机C程序代写及protues的仿真图。
店主10余年电子开发经验为您提供专业的服务。
另外,代画protel原理图和代做PCB图。
============================================
有需要代写的请与我,价格商讨((咨询特价)起),尽量满足您的要求,程序具体要求,请与我,谢谢!
方式
在线客服:
在线89
邮箱:89@qq.com
谢谢!
可提供自制的PCB电路板
以下介绍个程序实例:
DS1302时钟+液晶显示ADC+串行口
/*******************************************************************************
Project : ADC&LCD1602&DS1302&USART应用
Clock F : 3.6864MHz
Version : 09.04.03-09.(咨询特价)
comments:
1、串口发送命令'1'开启一次ADC,并将结果通过串口发送到PC,同时在LCD1602上显示;
2、PC和LCD1602也同时显示每次更新ADC转换结果的时间;
3、USART使用中断方式接收数据,当接收到指定数据后,开启一次ADC转换;
4、当ADC转换完成后产生中断,并置位一个自定义的标志;
5、检测ADC转换完成后的中断标志,为1时则将ADC转换数据发送给PC,同时在LCD1602显示;
6、4种不同的配置方驶
*******************************************************************************/
#include <iom16v.h>
#include <macros.h>
#include "ds1302.h"
#include "LCD1602.h"
#include "usart.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uint AdcData; //存放ADC转换的结果
uchar AdcConCom = 0; //ADC转换完成标志
/*-----------------------------------------------------------------
函数名称: void AdcInit(void)
函数功能: ADC初始化
参 数:
返 回 值: 无
-----------------------------------------------------------------*/
void AdcInit(void)
{
ADCSR = 0x00; //ADC关闭
ADMUX = 0x67; //1:外部参考源AVCC,左对齐,选择ADC7通道
//ADMUX = 0x46; //2:外部参考源AVCC,右对齐,选择ADC7通道
//ADMUX = 0xE0; //3:2.56V 的片内基准电压源,左对齐,选择ADC0通道
//ADMUX = 0xC1; //4:2.56V 的片内基准电压源,右对齐,选择ADC0通道
ACSR = 0x80; //模拟比较器控制和状态寄存器ACSR的ACD置1,使模拟比较器禁用
ADCSR = 0x8B; //开启ADC,8分频,ADC中断使能
}
/*-----------------------ADC转换中断程序--------------------------------------*/
#pragma interrupt_handler adc_isr:15
void adc_isr(void)
{
AdcData=(uint)((ulong)ADCH * 4930 / 256); //1:将AD值转换为电压值(只读高8位)
//AdcData=(uint)((ulong)ADC * 4930 / 1024); //2:将AD值转换为电压值(读所有位)
//AdcData=(uint)((ulong)ADCH * 2635 / 256); //3:将AD值转换为电压值(只读高8位)
//AdcData=(uint)((ulong)ADC * 2635 / 1024); //4:将AD值转换为电压值(读所有位)
AdcConCom = 1; //置ADC转换完成标志
}
/*-----------------------------------------------------------------
函数名称: void InitDevices(void)
函数功能: 初始化各种信息
参 数:
返 回 值: 无
-----------------------------------------------------------------*/
void InitDevices(void)
{
CLI(); //关全部中断
Usart_init03(); //中断方式初始化
Port_init();
AdcInit();
ds1302_init(); //DS1302初始化
delay_ms(10);
ds1302_write_time(); //写入初始值
LCD_init(); //LCD初始化
LCD_clear();//清屏
LCD_write_str(0,0,"09-04-05 ACDtest");
LCD_write_str(0,1,"ADC is so easy!");
//delay_ms(2000);
MCUCR = 0x00;
SEI(); //开全中断
}
void main(void)
{
uchar temp;
InitDevices();
while(1)
{
if(AdcConCom)
{
AdcConCom = 0; //清ADC转换完成标志
//将电压值发送给PC
USART_Transmit(AdcData/1000 + 0x30); //得到电压值的千位并发送
USART_Transmit('.'); //发送小数点
USART_Transmit(AdcData%1000/100 + 0x30); //得到电压值的百位并发送
USART_Transmit(AdcData%100/10 + 0x30); //得到电压值的十位并发送
USART_Transmit(AdcData%10 + 0x30); //得到电压值的个位并发送
USART_Transmit('V'); //发送电压符号"V"
newline(); //换行
//读取时间并将其显示在LCD1602上
ds1302_read_time(); //读取时间
LCD_clear(); //清屏
temp = (time_buf[0] >> 4) + '0';
LCD_write_char(0, 1, temp);/*年*/
USART_Transmit(temp);
temp = (time_buf[0] & 0x0F) + '0';
LCD_write_char(1, 1, temp);
USART_Transmit(temp);
temp = (time_buf[1] >> 4) + '0';
LCD_write_char(2, 1, temp);
USART_Transmit(temp);
temp = (time_buf[1] & 0x0F) + '0';
LCD_write_char(3, 1, temp);
USART_Transmit(temp);
LCD_write_char(4, 1, '-');
USART_Transmit('-');
temp = (time_buf[2] >> 4) + '0';
LCD_write_char(5, 1, temp);/*月*/
USART_Transmit(temp);
temp = (time_buf[2] & 0x0F) + '0';
LCD_write_char(6, 1, temp);
USART_Transmit(temp);
LCD_write_char(7, 1, '-');
USART_Transmit('-');
temp = (time_buf[3] >> 4) + '0';
LCD_write_char(8, 1, temp);/*日*/
USART_Transmit(temp);
temp = (time_buf[3] & 0x0F) + '0';
LCD_write_char(9, 1, temp);
USART_Transmit(temp);
blank();
//temp = (time_buf[7]) + '0';
//LCD_write_char(1, 1, temp); //不显示周
temp = (time_buf[4] >> 4) + '0';
LCD_write_char(11, 1, temp); //时
USART_Transmit(temp);
temp = (time_buf[4] & 0x0F) + '0';
LCD_write_char(12, 1, temp);
USART_Transmit(temp);
LCD_write_char(13, 1, ':');
USART_Transmit(':');
temp = (time_buf[5] >> 4) + '0';
LCD_write_char(14, 1, temp);/*分*/
USART_Transmit(temp);
temp = (time_buf[5] & 0x0F) + '0';
LCD_write_char(15, 1, temp);
USART_Transmit(temp);
newline(); //换行
//LCD_write_char(13, 1, ':');
//temp = (time_buf[6] >> 4) + '0';
//LCD_write_char(14, 1, temp); //秒不显示
//temp = (time_buf[6] & 0x0F) + '0';
//LCD_write_char(15, 1, temp);
//将电压值显示在LCD1602上
LCD_write_char(0, 0, 'A');
LCD_write_char(1, 0, 'D');
LCD_write_char(2, 0, 'C');
LCD_write_char(3, 0, '=');
LCD_write_char(4, 0, AdcData/1000 + 0x30);
LCD_write_char(5, 0, '.');
LCD_write_char(6, 0, AdcData%1000/100 + 0x30);
LCD_write_char(7, 0, AdcData%100/10 + 0x30);
LCD_write_char(8, 0, AdcData%10 + 0x30);
LCD_write_char(9, 0, 'V');
}
}
}
-
最近销售:0 掌柜:灵儿电子工作室¥75 元
-
最近销售:0 掌柜:灵儿电子工作室¥75 元
-
最近销售:0 掌柜:灵儿电子工作室¥75 元