Học liệu

ĐIỀU KHIỂN HỆ THỐNG SẤY MÂM VỚI KỸ THUẬT MỜ

  • 27/11/2020
  • Học liệu

#include "msp430.h"
#define DATA BIT3 // DS -> 2.3
#define CLOCK BIT4 // SH_CP -> 2.4
#define LATCH BIT5 // ST_CP -> 2.5
unsigned int a,f,m;
unsigned long chuc2,donvi2,p;
unsigned int chuc1,donvi1;
unsigned char tlsb,tmsb;
unsigned char i;
unsigned int led7[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//anode chung
void pinWrite( unsigned int bit, unsigned char val )
{
if (val)
{
P2OUT |= bit;
}
else
{
P2OUT &=~bit;
}
}
void pulseClock( void )
{
P2OUT |= CLOCK;
P2OUT ^= CLOCK;

}
void shiftOut(unsigned char val)
{
P2OUT &= ~LATCH;
unsigned int i;
for (i = 0; i < 8; i++)
{
pinWrite(DATA, (val & (1<<i)));
pulseClock();
}
P2OUT |= LATCH;
P2OUT &=~LATCH;
}
void dich(unsigned int v )
{ unsigned int i;
{ for (i=0;i<8;i++ )
{
shiftOut(v);
}
}
}
void hienthi(unsigned long k,unsigned int e )
{
p=(k*100/1023);//tuong ung do am
chuc1= p/10;
donvi1= p%10;
chuc2 = e/10; //tuong ung nhiet do
donvi2= e % 10;
dich(led7[chuc2]);//hien thi nhiet do
P1OUT|=BIT6; //chon led hien thi
__delay_cycles(900);//delay cho led sang
P1OUT&=~BIT6;

dich(led7[donvi2]);
P1OUT|=BIT7;
__delay_cycles(900);
P1OUT&=~BIT7;
dich(led7[chuc1]);//hien thi do am
P1OUT|=BIT3;
__delay_cycles(900);
P1OUT&=~BIT3;
dich(led7[donvi1]);
P1OUT|=BIT4;
__delay_cycles(900);
P1OUT&=~BIT4;
}
void delay(unsigned int j) //micro giay
{
for(;j>0;j--);
}

unsigned char ow_reset(void)
{
unsigned char presence;
P1DIR |=BIT2;
P1OUT &=~BIT2;
delay(60);
P1OUT |=BIT2;
delay(10);
P1DIR &=~BIT2;
presence = P1IN;
delay(45);
return(presence);
}

unsigned char read_byte(void)
{
unsigned char value = 0;
for (i=8;i>0;i--)
{
value>>=1;
P1DIR |=BIT2;
P1OUT &=~BIT2;
_NOP();
_NOP();
P1DIR &=~BIT2;
if(P1IN&BIT2)value|=0x80;
delay(8);
}
return(value);
}

void write_byte(char val)
{
unsigned char i;
P1DIR |=BIT2;
for (i=8; i>0; i--)
{
P1OUT &=~BIT2;
_NOP();
if(val&0x01)P1OUT |=BIT2;
else P1OUT &=~BIT2;
delay(12);
P1OUT |=BIT2;
val>>=1;
}
delay(10);
}
//....................................................
unsigned int nhietdo()
{ unsigned int t;
union
{
unsigned int c[2];
int x;
} t0;

P1OUT |=BIT2;

ow_reset();
write_byte(0xCC); //Skip ROM
write_byte(0x44); // bat dau chuyen doi

ow_reset();
write_byte(0xCC); // Skip ROM
write_byte(0xBE); // Read Scratch Pad
t0.c[0]=read_byte();
t0.c[1]=read_byte();
P1OUT &=~ BIT2;
tlsb=t0.c[0]>>4;
tmsb=t0.c[1]<<4;
t= tlsb + tmsb;
return t;
}
long doam(void)
{ long d;
{
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
__enable_interrupt(); // CHO PHEP NGAT
TACCR0 = 30; // TAO TRE THIET LAP DIEN THE THAM CHIEU
TACCTL0 |= CCIE; // SO SANH CHE DO NGAT
TACTL = TASSEL_2 | MC_1;
TACCTL0 &= ~CCIE; //CAM NGAT TIMER
__disable_interrupt();
ADC10CTL1 = INCH_1; // CHON KENH A1,A0
ADC10AE0 |= BIT1; //CHO PHEP A1 CHUYEN DOI
ADC10CTL0 |= ENC + ADC10SC; // BAT DAU CHUYEN DOI
d=ADC10MEM;
}return d;
}
void chinhxung(void)
{

P2OUT&=~BIT1;
hienthi(a,f);
P2OUT|=BIT1;
f=nhietdo();
a=doam();
hienthi(a,f);

}

//************************//

void main(void)
{
P1DIR|=(BIT7+BIT3+BIT6+BIT4+BIT2+BIT5+BIT1);
P2DIR |= (DATA + CLOCK + LATCH+BIT1+BIT2);
P2OUT&=~BIT2;//den
P2OUT|=BIT1;//quat
WDTCTL = WDTPW + WDTHOLD;
unsigned int a,f;
while(1)
{
if((P2IN&BIT0)==0)
{ f=nhietdo();
a=doam();
hienthi(a,f);
if(a>0x88) //tuong ung 0.2v//(136*100/1023)
{ P1OUT&=~BIT5;//xoa bit bao do am
if(f<0x21) //NHO HON 33 THI MO DEN,
{
P2OUT|=BIT2;//den//
for(int r=0;r<30;r++)
{
chinhxung();
}
}
else
{
P2OUT&=~BIT2;//DEN
P2OUT&=~BIT1;//quat
hienthi(a,f);
f=nhietdo();
a=doam();
hienthi(a,f);
f=nhietdo();
a=doam();
hienthi(a,f);

}
}

else
{
P2OUT&=~BIT2;
P2OUT|=BIT1;
P1OUT|=BIT5;
}
}
else
{
P2OUT&=~BIT2;
P2OUT|=BIT1;
P1OUT&=~BIT5;
hienthi(0,0);
}
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
}

 

 

Các tin khác