主程序----main.c
#define ALLOCATE_EXTERN
#include "HC89S003F4.h"
#include "stdio.h"
#include "gpio.h"
#include "uart.h"
#define AD_num 10 //通道数
unsigned int gui_AdcValue_a[AD_num] = {0x00};
//存放转换后的数值
unsigned char guc_AdcChannel_a[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
//ADC通道预设置
unsigned char guc_Count = 0; //通道计数
char sendbuf[] = " I'm the Id ";
char getbuf[20];
unsigned int flag=0,num=5,i=0,mode=0;
/***************************************************
主程序
****************************************************/
void main()
{
WDTCCR = 0x00;
CLKSWR = 0x51;
CLKDIV = 0x01;
/**********************************UART端口设置¯**************************************/
// P2M0 = P2M0&0x0F|0x80; //P21TX
GPIO(P10,IO_OUT_OD); //P10TX
// P0M1 = P0M1&0x0F|0x20; //P03RX
GPIO(P11,IO_IN_FL_NO_SMT); //P11TX
// TXD_MAP = 0x21; //TX端口映射到P21
TXD_MAP = 0x10; //TX端口映射到P10
// RXD_MAP = 0x03; //RX端口映射到P03
RXD_MAP = 0x11; //RX端口映射到P11
T4CON = 0x06; //模式6
//波特率 38400---FFE6
//波特率 9600---FF98
TH4 = 0xFF;
TL4 = 0xE6;
SCON2 = 0x02;
SCON = 0x10;
IE |= 0X10;
EA = 1;
/************************************ADC设置*****************************************/
GPIO(P00,IO_IN_AN);
GPIO(P01,IO_IN_AN);
GPIO(P02,IO_IN_AN);
GPIO(P03,IO_IN_AN);
GPIO(P04,IO_IN_AN);
GPIO(P05,IO_IN_AN);
GPIO(P06,IO_IN_AN);
GPIO(P07,IO_IN_AN);
GPIO(P20,IO_IN_AN);
GPIO(P21,IO_IN_AN);
ADCC0 = 0x80;
Delay_2us(10);
ADCC1 = 0x00;
ADCC2 = 0x4D;
IE1 |= 0x20;
EA = 1;
ADCC0 &=~ 0x20;
Delay_2us(10);
ADCC0 |= 0x40;
while(1)
{
printf("AD_a");
for(i=0;i<AD_num;i++)
{
printf(" %d ",gui_AdcValue_a[i]);
}
printf("\r\n");
Delay_ms(500);
}
}
}
void adc_do(unsigned int ad_value)
{
gui_AdcValue_a[guc_Count] = ad_value;
guc_Count++;
if(guc_Count >=AD_num)guc_Count=0;
ADCC1 = (ADCC1&(~0x0f))|(guc_AdcChannel_a[guc_Count]);
Delay_2us(10);
}
/*******************************ADC中断**************************************/
void ADC_Rpt() interrupt ADC_VECTOR
{
ADCC0 &=~ 0x20;
adc_do(ADCR);
ADCC0 |= 0x40;
}
/**********************************串口中断**************************************/
void UART1_Rpt(void) interrupt UART1_VECTOR
{
char temp;
if(SCON & 0x01)
{
temp= SBUF;
// if(flag==0) uart_do(temp);
SCON &=~ 0x01;
}
}
|
———————————————— 版权声明:本文为CSDN博主「追光拾忆者」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_39106660/article/details/105032413