⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btm48._c

📁 AVR ICC基于AVR单片机的LED显示程序!
💻 _C
字号:
#include <iom48v.h>
#include "bt.h"
#include "PT100.h"
#include <macros.h>
#include <eeprom.h>

#define uchar unsigned char
#define unit unsigned int
#define ulong unsigned long



#define xtal 8 
#define fosc 8000000 //晶振8MHZ
#define baud 9600	 //波特率


#define VTest PORTC|=0X80     //测量端口电压 
#define TestIO ((PINB&0X01)==0X01) //测量频率


//Watchdog initialize
// prescale: 16K
void watchdog_init(void)
{
 WDR(); //this prevents a timout on enabling
 WDTCSR = 0x0B; //WATCHDOG ENABLED - dont forget to issue WDRs
}




/*  		字符输出函数 		 */
void putchar(unsigned char c)
	{	 
    while (!(UCSR0A&(1<<UDRE0)))WDR();
	 UDR0=c; 
	// del(200);   
    }
	
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
void uart0_init(void)
{
 UCSR0B = 0x00; //disable while setting baud rate
 UCSR0A = 0x02;
 UCSR0C = 0x06;
 UBRR0L = 0x67; //set baud rate lo
 UBRR0H = 0x00; //set baud rate hi
 UCSR0B = 0x18;
}


unsigned long adc_rel[8];//AD转换结果
unsigned char adc_mux;//AD通道

//ADC initialize
// Cpbversipb time: 3uS
void adc_init(void)
{
 ADCSRA = 0x00; //disable adc
 ADMUX = 0x40; //select adc input 0  00-ref  01-avcc 11-2.56
 ACSR  = 0x80;
 ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) ;//64分频
}


unit cw(uchar mux)          ///*****检测信号*****///
{
 ADMUX=(1<<REFS0)|(mux&0x0f);
 ADCSRA|=0x40;
 del(200);
 return(ADC);
}

unit cw1(uchar mux)          ///*****检测信号*****///
{
unit adc_rel=0,a;
uchar i;
 for(i=0;i<5;i++)
  {
  adc_rel+=cw(mux);
  WDR();
  }
 return (unit)(adc_rel/5); 
}


//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 watchdog_init();
 adc_init();

 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EIMSK = 0x00;
 
 TIMSK0 = 0x00; //timer 0 interrupt sources
 TIMSK1 = 0x00; //timer 1 interrupt sources
 TIMSK2 = 0x00; //timer 2 interrupt sources
 
 PCMSK0 = 0x00; //pin change mask 0 
 PCMSK1 = 0x00; //pin change mask 1 
 PCMSK2 = 0x00; //pin change mask 2
 PCICR = 0x00; //pin change enable 
 PRR = 0x00; //power controller
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}



void main(void)
{
unit n=11100;
uchar ii=0;
unit Counter,Rx,TH,Zb,TL;

init_devices();

//*测量占空比
while(1)
{
PORTB|=0X01;DDRB&=~0X01;
Counter=0;Rx=0;     
while(!TestIO);
while(TestIO);

TCNT1H = 0x00;  TCNT1L = 0x00; TCCR1B = 0x02;
while(!TestIO);                      //高电平时间
TH=0xffff*Counter+TCNT1;
while(TestIO);
while(!TestIO);
TCNT1H = 0x00;  TCNT1L = 0x00; TCCR1B = 0x02;
while(TestIO);                       //di电平时间
TL=0xffff*Counter+TCNT1;
}

/*测量高电平时间
while(1)
{
PORTB|=0X01;
DDRB&=~0X01;
Counter=0;     //高电平时间
while(!TestIO);
while(TestIO);
TCNT1H = 0x00;  TCNT1L = 0x00; TCCR1B = 0x02;
while(!TestIO);
TCCR1B = 0x00;
Counter=0xffff*Counter+TCNT1H*0xff+TCNT1L;
if(Counter<9999)show4(Counter) ; 
}
//*测量电压
while(1)
{
dat=0;
delay1(100);
dat=cw1(7);
Rx=dat*(5000/1024);
show41(Rx,1) ; 
}

/*测量温度
while(1)
{
delay(100);
dat=cw1(5);
Rx=((1024-dat)*R*100)/dat;
show4( PT100(Rx)) ;    
}
*/

while(1)
{

delay(10);
show4(PT100(cw1(5)),1);        


}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -