全部代码:
#include <iostm8s103f2.h>
#include "english_6x8_pixel.h"
#include "picture84x48.h"
#include "Nokia_5110.h"#define uint unsigned int
#define uchar unsigned char
void IO_config(void);
void Delay1ms(unsigned int count);
void nokia_5110_picture();//写一屏图
void ADC_change(void);
float ad_temp;
uint AD_result,AD_result1;
uchar AD_data[10]={0};
/***********端口配置******************/
void IO_config(void)
{
PC_DDR_DDR5=1;
PC_DDR_DDR6=1;
PC_DDR_DDR7=1;
PC_DDR_DDR4=1;
PC_DDR_DDR3=1;
PC_CR1_C15=1;
PC_CR1_C16=1;
PC_CR1_C17=1;
PC_CR1_C14=1;
PC_CR1_C13=1;
PC_CR2 = 0x00;
}
/***********************************/
/************毫秒延时程序********************/
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
/**********************************************/
void nokia_5110_picture()//写一屏图
{
uchar e;
uchar t;
uchar k;
uint d;
d=0;
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
e=dal[d];
write_byte(e,1);
d=d+1;
}
}
}
/**************************************/
void ADC_change(void)
{
ADC_CR1 |= 0x01; // 打开AD模块电源
Delay1ms(50); // 延时至少100uS,用于等待采样保持电容充电至稳定
ADC_CR1 |= 0x01; // 启动AD转换
ADC_CSR &= 0x7F;
while(!(ADC_CSR & 0x80)); // 等待AD转换完成
AD_data[5]=ADC_DRH;
AD_data[6]=ADC_DRL;
AD_result1=(AD_data[5]*256)+AD_data[6];
ad_temp=(AD_result1*(float)3300)/(float)1024;
AD_result=(uint)ad_temp;
AD_data[0]=(uchar)(AD_result/1000);
AD_data[1]=(uchar)((AD_result%1000)/100);
AD_data[2]=(uchar)(((AD_result%1000)%100)/10);
AD_data[3]=(uchar)(((AD_result%1000)/100)%10);
ADC_CR1 &= 0xFE;
}
/*****************主程序********************/
void main(void)
{
IO_config();
LCD_Init(); //初始化液晶
LCD_Clear();
nokia_5110_picture();
Delay1ms(10000);
LCD_Clear();
LCD_write_english_string(0,0,"AD3= V");
LCD_write_english_string(0,1,"AD4= V");
ADC_CR1 = 0x62; // 设置AD转换时钟1/12,连续转换模式
ADC_CR2 = 0x08; // 设置数据为右对齐
ADC_CR3 = 0x00; // 不使用数据缓冲
while(1)
{
ADC_CSR = 0x03; // 选择AD转换通道3
ADC_change();
LCD_set_XY(24,0);
LCD_write_char( AD_data[0]+0x30);
LCD_write_char( '.');
LCD_write_char(AD_data[1]+0x30);
LCD_write_char(AD_data[2]+0x30);
LCD_write_char(AD_data[3]+0x30);
Delay1ms(50);
}
|