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

📄 cyclelower65535us.c

📁 ATmega16应用例子
💻 C
字号:
/*********************************************************************
微 雪 电 子   WaveShare   http://www.waveShare.net            	

目    的:   建立使用OC0做PWM的测试程序

目标系统:   基于AVR单片机

应用软件:   ICCAVR

版    本:   Version 1.0                                                          

圆版时间:   2005-06-25

开发人员:   SEE

说	 明:   若用于商业用途,请保留此段文字或注明代码来源

深 圳 微 雪 电 子 保 留 所 有 的 版 权     
*********************************************************************/

/*01010101010101010101010101010101010101010101010101010101010101010101
----------------------------------------------------------------------
版本更新记录:
版    本:   Version 1.1
圆版时间:   2005-03-25

----------------------------------------------------------------------
接入模块: 
接口说明: 
----------------------------------------------------------------------
注意事项:

----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/

#include <iom16v.h>
#include "D:\ICC_H\CmmICC.H"

/* lcd control and data port direction */
#define LCD_DDR_OUT {DDRA|= 0xF0;DDRD |= 0xE0;}

/* control port */
#define SET_RS  sbi(PORTD,5)
#define CLR_RS  cbi(PORTD,5)
#define SET_RW  sbi(PORTD,6)
#define CLR_RW  cbi(PORTD,6)
#define SET_E   sbi(PORTD,7)
#define CLR_E   cbi(PORTD,7)

/* data port */
#define SET_D4  sbi(PORTA,4)
#define CLR_D4  cbi(PORTA,4)
#define SET_D5  sbi(PORTA,5)
#define CLR_D5  cbi(PORTA,5)
#define SET_D6  sbi(PORTA,6)
#define CLR_D6  cbi(PORTA,6)
#define SET_D7  sbi(PORTA,7)
#define CLR_D7  cbi(PORTA,7)

/* busy port */
#define GET_BF	gbi(PINA,7)
#define OUT_BF	sbi(DDRA,7)
#define IN_BF	cbi(DDRA,7)

#include "D:\ICC_H\LCD1602_.H"

uint32 cycle;  
uint16 T1OvfTimes=0;

void port_init(void)
{
	PORTA = 0xFF;
	DDRA  = 0x00;
	PORTB = 0xFF;
	DDRB  = 0x00;
	PORTC = 0xFF; //m103 output only
	DDRC  = 0x00;
	PORTD = 0xFF;
	DDRD  = 0x00;
}

//TIMER1 initialisation - prescale:1024
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1Hz
// actual value:  1.000Hz (0.0%)
void timer1_init(void)
{
	TCCR1B = 0x00;	//stop
	TCNT1 = 0; 		//setup
	ICR1 =  0;
	TCCR1A = 0x00;
	TCCR1B = 0xC2;	//start Timer, Timer source=CLK/8
}

#pragma interrupt_handler timer1_capt_isr:6
void timer1_capt_isr(void)
{
	TCCR1B = 0x00; //stop
	//frq=(ICR1+86);
	//frq=TIME_1S/frq;	 // read (int)value in ICR1 using
	cycle=ICR1-24;
	//cycle = 1000000;
	if(T1OvfTimes!=0)
		cycle += (uint32)T1OvfTimes*65535;
	T1OvfTimes = 0;
	ICR1=0;
	TCNT1=0;
	TCCR1B=0XC2;
}

#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
	T1OvfTimes++;
}


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

	MCUCR = 0x00;
	GICR  = 0x00;
	TIMSK = 0x24; //timer interrupt sources
	SEI(); //re-enable interrupts
	//all peripherals are now initialised
}

void main(void)
{
	init_devices();
	LCD_DDR_OUT;
	DDRB = 0X00;	//set ICP port as input

	LCD1602_init();
	LCD1602_puts(0x80,"Cycle:   s ms us");
	while(1)
	{ 
		LCD1602_putd(0xcf,cycle,7);
		//LCD1602_putd(0xcd,cycle/1000,7);
		delay50ms(10);
	}
}

⌨️ 快捷键说明

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