مدار آتش یکسوسازها

omidvarshoei

عضو جدید
مدار آتش یکسوسازها در چند mode مختلف با زاویه آتش قابل تغییر .

This program was produced by the
CodeWizardAVR V1.24.4 Standard
Automatic Program Generator
© Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
e-mail:office@hpinfotech.com

Project :
Version :
Date : 5/18/2009
Author : l
Company : l
Comments:


Chip type : ATmega8
Program type : Application
Clock frequency : 1.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
Data Stack size : 256
*****************************************************/

#include <mega8.h>
#include <delay.h>
#include <stdio.h>

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
char bufer[10];
int key2,i,key,b,mode,count,g=0,h,f,ab;
unsigned int time1,time180,time2,time60,time120,time3,time4;

// External Interrupt 0 service routine




interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here

}

#define ADC_VREF_TYPE 0xC0
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}



interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Place your code here
if(mode==1){
if(h==0){
PORTD=0x01;
TCNT1=time180;
TCCR1B=0x01;
h=1;
g=0;
}
g++;
if(g>1){
if(g==2)
PORTD=0x02;
if(g==3){
PORTD=0x01;
g=1;
}
TCNT1=time180;
TCCR1B=0x01;
}
}
if(mode==2){
if(h==0){
PORTD=0x03;
TCNT1=time180;
TCCR1B=0x01;
h=1;
g=0;
}
g++;
if(g>2){
if(g==3)
PORTD=0x0c;
if(g==4){
PORTD=0x03;
g=2;
}
TCNT1=time180;
TCCR1B=0x01;
}
}
if(mode==3){
if(h==0){
PORTD=0x01;
TCNT1=time120;
TCCR1B=0x01;
h=1;
g=0;
}
g++;
if(g>2){
if(g==3)
PORTD=0x02;
if(g==4)
PORTD=0x04;
if(g==5){
PORTD=0x01;

g=2;
}
TCNT1=time120;
TCCR1B=0x01;
}
}
if(mode==4){
g++;
if(h==0){
PORTD=0x01;
TCNT1=time60;
TCCR1B=0x01;
h=1;
g=2;
}
if(g>2){
TCNT1=time60;
if(g==3)
PORTD=0x02;
if(g==4)
PORTD=0x04;
if(g==5)
PORTD=0x08;
if(g==6)
PORTD=0x10;
if(g==7)
PORTD=0x20;
if(g==8){
PORTD=0x01;
g=2;
}
}

}

}




// Declare your global variables here
int set_key(void);
int set_angle(void);
void main(void)
{
// Declare your local variables here
char bufer1[10];
float value,t,t120,t60,div;
unsigned int var,angle;


PORTB=0x00;
DDRB=0x00;

PORTC=0x00;
DDRC=0x00;

PORTD=0x00;
DDRD=0xFF;

TCCR0=0x00;
TCNT0=0x00;

TCCR1B=0x00;
TCCR1A=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

GICR|=0x40;
MCUCR=0x03;
GIFR=0x40;


TIMSK=0x04;


// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: Int., cap. on AREF
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x83;


ACSR=0x80;
SFIOR=0x00;

// LCD module initialization
#asm("cli")
lcd_init(16);
mode=1;
lcd_clear();
lcd_putsf("ENTER THE MODE");
//goto loop1;
goto br;

loop1:
while(1){
key=set_key();
if(key>4){
key=0;
i=0;
}
mode=key;
lcd_clear();
sprintf(bufer,"NUMBER OF MODE:%i",key);
lcd_puts(bufer);
delay_ms(500);
key2 =PINC.3 & 0x01;
if(key2 ==0x01){
delay_ms(50);
key2 =PINC.3 & 0x01;
if(key2 ==0x01)
b=1;
}
if(key>0 & b==1){
lcd_clear();
lcd_putsf("MODE IS ACCEPT");
delay_ms(500);
lcd_clear();
lcd_gotoxy(0,0);
sprintf(bufer1,"MODE=%i",mode);
lcd_puts(bufer1);
delay_ms(1000);
goto angel;
}
}
br:
switch(key)
{
case 1:
goto mode1;
case 2:
goto mode2;
case 3:
goto mode3;
case 4:
goto mode4;
case 0:
goto loop1;
}

AD: //////////////////////////
var=read_adc(0);
var=var+1;
value=var*2.56;
value=value/1023;
if(value>0 && value<2)
{
goto atash;
}
else
{
goto AD;
}


atash: /////////////////////////////
if(mode==1){
TCNT1=time1;
TCCR1B=0x01;
h=0;
#asm("sei")
g++;
while (1){
}
}
if(mode==2){
TCNT1=time2;
TCCR1B=0x01;
h=0;
#asm("sei")
g=1;
while(1){
}
}
if(mode==3){
TCNT1=time3;
TCCR1B=0x01;
h=0;
#asm("sei")
g=1;
while(1){
}
}
if(mode==4){
TCNT1=time4;
TCCR1B=0x01;
h=0;
#asm("sei")
g=1;
while(1){
}
}

mode1:
mode=1;
angle=30;
lcd_clear();
lcd_putsf("mode=1");
div=angle/180;
t=0.01; ///////////time of f=50hz 1/f=0.02/2=0.01
t=0.01*div;
t=t/0.000001;
time1=65535-t;
t=0.01/0.000001;
time180=65535-t;
goto atash;


mode2:
mode=2;
lcd_clear();
lcd_putsf("mode=2");
div=angle/180;
t=0.01; ///////////time of f=50hz 1/f=0.02/2=0.01
t=0.01*div;
t=t/0.000001;
time2=65535-t;
t=0.01/0.000001;
time180=65535-t;
goto AD;


mode3:
mode=3;
div=180/angle;
t=0.01; ///////////time of f=50hz 1/f=0.02/2=0.01
t=t/div;
t=t/0.000001;
time3=65535-t;
t120=2*0.01/3;
t120=65535-t120;
t120=t120/0.000001;
time120=65535-t120;
TCCR1B=0x00;
goto AD;

mode4:
mode=4;
t60=0.01/3;
t60=t60/0.000001;
t60=65535-t60;
time60=t60;
div=180/angle;
t=0.01; ///////////time of f=50hz 1/f=0.02/2=0.01
t=t/div;
t=t/0.000001;
time4=65535-t;
TCCR1B=0x00;
goto AD;


angel:
f=0;
angle=0;
goto y;
y:
ab=set_angle();
angle=ab*12;
if (angle>170 | angle<0)
{
angle=168;
f=14;
}
sprintf(bufer,"ANGLE:%i DEG",angle);
lcd_gotoxy(0,1);
lcd_puts(bufer);
delay_ms(500);
b=0;
key2 =PINC.3 & 0x01;
if(key2 ==0x01)
{
delay_ms(50);
key2 =PINC.3 & 0x01;
if(key2 ==0x01)
{
b=1;
}
}
if (b==1)
goto br;
else
goto y;



}

int set_key(void)
{
key2 =PINC.1 & 0x01;
if(key2 ==0x01)
{
delay_ms(50);
key2 =PINC.1 & 0x01;
if(key2 ==0x01)
{
i++;
}
}
key2 =PINC.2 & 0x01;
if(key2 ==0x01)
{
delay_ms(50);
key2 =PINC.2 & 0x01;
if(key2 ==0x01)
{
i--;
}
}
if(i<0)
{
i=0;
}
return i;
}
int set_angle(void)
{
key2 =PINC.1 & 0x01;
if(key2 ==0x01)
{
delay_ms(50);
key2 =PINC.1 & 0x01;
if(key2 ==0x01)
{
f++;
}
}
key2 =PINC.2 & 0x01;
if(key2 ==0x01)
{
delay_ms(50);
key2 =PINC.2 & 0x01;
if(key2 ==0x01)
{
f--;
}
}
if(i<0)
{
i=0;
}
return f;
 

Similar threads

بالا