/*
* File: Vtest.c
* Author: Administrator
*
* Created on 2016?12?19?, ??9:05
*/
#include <stdio.h>
#include <stdlib.h>
#include <pic.h> //pic16f676
#define uchar unsigned char
#define uint unsigned int
#define buzz RC4
#define led RC5
//#define key RA5
unsigned char LED_DUAN[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
//无浮点
unsigned char LED_FloatNumber[17]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF,0x77,0x7C,0x39,0x5E,0x79,0x71,0X76};
// 0 1 2 3 4 5 6 7 8 9 A B C D E F H
unsigned int count;
unsigned int AD_sample=0;
unsigned int AD_result=0;
void delay_ms(uint time)
{
uint t,k;
for (t=0;t<time;t++)
{
for (k=0;k<80;k++);
}
}
void deal_ad()
{
ADCON0=0x81;
ADCON1=0x10;
ADSEL=0x01;
AD_sample=0;
ADON=1;
while(ADGO)
AD_sample=ADRESH<<8|ADRESL;
AD_result=AD_sample*5/1024;
//AD_result=AD_result/100;
count=AD_result;
}
void deal_buzzandled()
{
if((count>=410)&&(count<516))
buzz=1;
led=1;
delay_ms(10);
else(
PORTC=0x00;
);
if((count<410)&&(count<258))
//if(key==1)
buzz=1;
led=1;
delay_ms(10);
else(
PORTC=0x00;
);
}
void display()
{
LED_FloatNumber[AD_result/100];
delay_ms(10);
LED_DUAN[AD_result%100/10];
delay_ms(10);
LED_DUAN[AD_result%10];
delay_ms(10);
}
void main()
{
TRISA=TRISA|0X21;//RA0 shu ru
TRISC=0x00;//RC4 RC5 shu chu
PORTA=0x00;
PORTC=0x00;
deal_ad();
while(1)
{
// PORTC=0xff;
//delay_ms(10);
// PORTC=0x00;
display();
deal_buzzandled();
}
}
|