📄 signal-chanle.txt
字号:
#include "config.h"
#include "stdio.h"
//******************************
/*函数名称:delayns()*/
void delayns(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
for(i=0;i<5000;i++);
}
#define UART_BPS 115200 //通信波特率9600
//******************************
/*函数名称:UART0_Init()*/
void UART0_Init(void)
{
uint16 Fdiv;
U0LCR=0x83; //DLAB=1
Fdiv=(Fpclk/16)/UART_BPS;
U0DLM=Fdiv/256;
U0DLL=Fdiv%256;
U0LCR=0x03;
}
/**************************************/
/*函数名称:UART0_SendByte()*/
void UART0_SendByte(uint8 data)
{
U0THR=data;
while((U0LSR&0x40)==0); //等待数据发送完毕
}
/**************************************/
/*函数名称:PC_DispChar()*/
void PC_DispChar(uint8 x,uint8 y,uint8 chr,uint8 color)
{
UART0_SendByte(0xff); //起始字符
UART0_SendByte(x);
UART0_SendByte(y);
UART0_SendByte(chr);
UART0_SendByte(color);
}
/**************************************/
/*函数名称:ISendStr()*/
void ISendStr(uint8 x,uint8 y,uint8 color,char *str)
{
while(1)
{ if(*str =='\0') break; //结束字符
PC_DispChar(x++,y,*str++,color);
if(x>=80)
{ x=0;
y++;
}
}
}
/**************************************/
/*函数名称:main()*/
int main(void)
{
uint32 ADC_Data;
char str[20];
PINSEL0=0X00000005; //引脚连接串口
PINSEL1=1<<28; //P0.30连接到AD0.3
UART0_Init();
/*进行ADC模块设置*/
AD0CR = (1<<3) | //SEL=8,选择通道3
((Fpclk/1000000 -1)<<8) |
(0<<16) |
(0<<17) |
(1<<21) |
(0<<22) |
(1<<24) |
(0<<27) ;
delayns(10);
ADC_Data = AD0DR;
while(1)
{ AD0CR |=1<<24;
while((AD0DR&0x80000000)==0);
AD0CR |=1<<24;
while((AD0DR&0x80000000)==0);
ADC_Data=AD0DR;
ADC_Data=(ADC_Data>>6)&0x3ff;
ADC_Data=ADC_Data*2480;
ADC_Data=ADC_Data/1024;
sprintf(str,"% 4d mv VIN3",ADC_Data);
ISendStr(0,0,0x30,str);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -