Thông báo

Collapse
No announcement yet.

thiết kế mạch điều khiển máy bơm nước dùng ATMEGA16L

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • thiết kế mạch điều khiển máy bơm nước dùng ATMEGA16L

    em đang làm mạch điều khiển hệ thống bơm tưới cây cảnh sử dụng atmega16l ,nguyên tắc đơn giản đó là hẹn giờ bơm nước bằng thời gian thực ví dụ từ 4-6h sáng và đặt giờ bơm trong khoảng thời gian bao lâu ví dụ như bơm thêm 10p yêu cầu hiển thị bằng LCD...Chỉ có hai chế độ thôi,phần code em tự viết trên nền Codevisionavr đã dịch ra file hex nhưng k hiểu sao em nạp vào mô phỏng trên proteus thì LCD k hiển thị được.Em xem đi xem lại rồi mà vẫn k biết mình sai ở đâu,bác nào xem rồi cho em ý kiến với,2 tuần nữa là em nộp rồi mà vẫn còn bề bộn thế này .Cảm ơn các bác nhiều!
    Code:
    /*****************************************************
    This program was produced by the
    CodeWizardAVR V2.05.6 
    Automatic Program Generator
    © Copyright 1998-2012 Pavel Haiduc, HP InfoTech s.r.l.
    http://www.hpinfotech.com
    
    Project : 
    Version : 
    Date    : 12/4/2013
    Author  : Cracked By PerTic@n (Evaluation)
    V1.0 - SonSivRi.to
    Company : 
    Comments: 
    
    
    Chip type               : ATmega16L
    Program type            : Application
    AVR Core Clock frequency: 16.006000 MHz
    Memory model            : Small
    External RAM size       : 0
    Data Stack size         : 256
    *****************************************************/
    
    #include <mega16.h>
    #include <delay.h>
    
    // I2C Bus functions
    
    #asm
       .equ i2c_port=0x15 ;PORTC
       .equ sda_bit=1
       .equ scl_bit=0   
     #endasm    
     #define MODE PORTB.0
     #define UP   PORTB.1   
     #define DOWN PORTB.2
     #define SET  PORTB.3
     #define START PORTB.4
    // DS1307 Real Time Clock functions
    #include <ds1307.h>
    #define STATUS              PORTB.5;
    
    // Declare your global variables here
    
    unsigned char h=0,s=0,m=0;
    unsigned int dem = 0, const_datgio =6   ;
    unsigned char dat_gio1=0,dat_gio2=0;
    unsigned char mode=0,set=0 , ;
    unsigned char hour_wait=0,minute_wait=0 ;
    unsigned char donvi,chuc,tram,nghin,data,x,y;                   
    unsigned char set_hour,  set_minute,set_seconds;
    bit mode0=1,mode1=1,set0=1,set1=1 , save_ds1307 = 0 ;
    
    
    //doc du lieu tu LCD
    
    // Alphanumeric LCD functions
    #include <alcd.h>
    #asm
       .equ __lcd_port=0x12 ;PORTD
    #endasm
        // External Interrupt 1 service routine
    interrupt [EXT_INT1] void ext_int1_isr(void)
    {
    // Place your code here
               delay_ms (100);
             dem=dem--;
    
    }
    
    // External Interrupt 2 service routine
    interrupt [EXT_INT2] void ext_int2_isr(void)
    {
    // Place your code here
                   delay_ms (100);
              dem=dem++;
    }
    
      void main(void)
    {
    {         
    
    // Declare your local variables here
    
    // Reset Source checking
    if (MCUCSR & 1)
       {
       // Power-on Reset
       MCUCSR&=0xE0;
       // Place your code here
    
       }
    else if (MCUCSR & 2)
       {
       // External Reset
       MCUCSR&=0xE0;
       // Place your code here
    
       }
    else if (MCUCSR & 4)
       {
       // Brown-Out Reset
       MCUCSR&=0xE0;
       // Place your code here
    
       }
    else if (MCUCSR & 8)
       {
       // Watchdog Reset
       MCUCSR&=0xE0;
       // Place your code here
    
       }
    else if (MCUCSR & 0x10)
       {
       // JTAG Reset
       MCUCSR&=0xE0;
       // Place your code here
    
       }
    
    // Input/Output Ports initialization
    // Port A initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTA=0x00;
    DDRA=0x00;
    
    // Port B initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=P State5=P State4=P State3=P State2=P State1=P State0=P 
    PORTB=0x7F;
    DDRB=0x00;
    
    // Port C initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=P State0=P 
    PORTC=0x03;
    DDRC=0x00;
    
    // Port D initialization
    // Func7=Out Func6=Out Func5=Out Func4=Out Func3=In Func2=Out Func1=Out Func0=Out 
    // State7=0 State6=0 State5=0 State4=0 State3=T State2=0 State1=0 State0=0 
    PORTD=0x00;
    DDRD=0xF7;
    
    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: 31.250 kHz
    // Mode: Normal top=0xFF
    // OC0 output: Disconnected
    TCCR0=0x03;
    TCNT0=0x00;
    OCR0=0x00;
    
    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: 250.094 kHz
    // Mode: Normal top=0xFFFF
    // OC1A output: Discon.
    // OC1B output: Discon.
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    // Timer1 Overflow Interrupt: Off
    // Input Capture Interrupt: Off
    // Compare A Match Interrupt: Off
    // Compare B Match Interrupt: Off
    TCCR1A=0x00;
    TCCR1B=0x03;
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x00;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;
    
    // Timer/Counter 2 initialization
    // Clock source: System Clock
    // Clock value: Timer2 Stopped
    // Mode: Normal top=0xFF
    // OC2 output: Disconnected
    ASSR=0x00;
    TCCR2=0x00;
    TCNT2=0x00;
    OCR2=0x00;
    
    // External Interrupt(s) initialization
    // INT0: off
    
    // INT1: off
    
    // INT2: Off
    
    GICR|=0xE0;
    MCUCR=0x0A;
    MCUCSR=0x40;
    GIFR=0xE0;
    
    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=0x01;
    
    // USART initialization
    // USART disabled
    UCSRB=0x00;
    
    // Analog Comparator initialization
    // Analog Comparator: Off
    // Analog Comparator Input Capture by Timer/Counter 1: Off
    ACSR=0x80;
    SFIOR=0x00;
    
    // ADC initialization
    // ADC disabled
    ADCSRA=0x00;
    
    // SPI initialization
    // SPI disabled
    SPCR=0x00;
    
    // TWI initialization
    // TWI disabled
    TWCR=0x00;
    
    // I2C Bus initialization
    // I2C Port: PORTC
    // I2C SDA bit: 1
    // I2C SCL bit: 0
    // Bit Rate: 100 kHz
    // Note: I2C settings are specified in the
    // Project|Configure|C Compiler|Libraries|I2C menu.
    i2c_init();
    
    // DS1307 Real Time Clock initialization
    // Square wave output on pin SQW/OUT: Off
    // SQW/OUT pin state: 0
    rtc_init(0,0,0);
    
    // Alphanumeric LCD initialization
    // Connections are specified in the
    // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
    // RS - PORTD Bit 0
    // RD - PORTD Bit 1
    // EN - PORTD Bit 2
    // D4 - PORTD Bit 4
    // D5 - PORTD Bit 5
    // D6 - PORTD Bit 6
    // D7 - PORTD Bit 7
    // Characters/line: 16
    lcd_init(16);
    
    // Timer 0 overflow interrupt service routine
    
    {
    // Place your code here
               TCNT0  =0x06  ;
               dem                     = dem++;
        if (dem >= 100)
        {
            dem                 = 0;
            s                = s + 1;
        } 
               
    }
    
    // Global enable interrupts
    delay_ms(100);
    delay_ms(100);
    delay_ms(100);
    #asm("sei")
        lcd_gotoxy(0, 0);
        lcd_puts("clkreal");
        lcd_gotoxy(0, 1);
        lcd_puts("TG BOM:"); 
        s       =rtc_read(0x00);  
        rtc_write(0x00,s&0x7f);  
    
    while (1)
              
          set_hour                     = rtc_read(0x02);  
          set_minute                 = rtc_read(0x01);    
          set_seconds                    = rtc_read(0x00);
          // Place your code here      
              while(PINB.0==0)
           {     
             
               {               
                   if((mode0==1)&&(mode1==0))
                 {
                    
                    {  
                     mode++  ;
                    if (mode>1)
                     mode=0;
                     }
                    
                  }
                }
    
                              switch (mode)
               {               
                             case 1 :
                               
                         {      
                           if(PINB.0==0)
                               mode=0;
                                   while(PINB.0==0);
                                   lcd_gotoxy(0, 0);
                                   lcd_puts("dat_gio:"); 
                             
                                   lcd_gotoxy(8, 0); 
                                   lcd_putchar(h/10+48);
                                   lcd_putchar(h%10+48); 
                                   lcd_putchar(':');
                                   lcd_putchar(m/10+48);
                                    lcd_putchar(m%10+48); 
                                   lcd_putchar(':');
                                  lcd_putchar(s/10+48);
                                 lcd_putchar(s%10+48);  
                       
                               if (PORTB.4 ==0)
                                lcd_gotoxy(0, 0);
                                         lcd_puts("editclk:");
                               
                                         lcd_gotoxy(8, 0); 
                                         lcd_putchar(h/10+48);
                                          lcd_putchar(h%10+48); 
                                         lcd_putchar(':');
                                         lcd_putchar(m/10+48);
                                         lcd_putchar(m%10+48); 
                                         lcd_putchar(':');
                                         lcd_putchar(s/10+48);
                                         lcd_putchar(s%10+48);   
                          
                               
                          {
                                     while(PINB.3 == 0)                                       
                                {                                                                   
                                  if((set0==1)&&(set1==0))
                               {
                                  set ++ ;
                                  if (set >3)
                                   set =0;
                                }
                             }
                                    switch (set ) 
                             {        
                                    case 1:
                                     
                                {
                                           
                                            set=0;
                                   {        
                                            
                                           delay_ms(100); 
                                       {
                                            while (PINB.4)
                                         {
                                         if(PINB.2)
                                         
                                              h   = h++;
                                          if (h >= 24)
                                           h         = 0; 
                                        }  
                                        
                                        {
                                         if(PINB.3)
                                          h  = h--;
                                       if (h <= 0)
                                        h         = 23; 
                                       }   
                                             
                                     }
                                            while(PINB.4) 
                                     {
                                          lcd_gotoxy(0, 0);
                                          _lcd_write_data(0x0F);  
                                       }
                                      break ;   
                                    }   
                                              
                                     case 2 :       
                                     set=1;
                                 {               
                                           
                                      delay_ms(100); 
                                      while (PINB.4)
                                   {
                                     if (PINB.1)  
                                      {    m            = m++;
                                          if (m >= 60)
                                           m   = 0; 
                                      }
    
                                       if(PINB.2) 
                                      {   m            = m-- ;
                                          if (m <= 0)
                                          m        = 59; 
                                      }  
                                     
                                   }
                                         while(PINB.3) 
                                      {
                                         lcd_gotoxy(0, 0);
                                          _lcd_write_data(0x0F);  
                                      };
                                      lcd_gotoxy(0, 0);
                                     _lcd_write_data(0x0C); 
                                        save_ds1307              = 1;   
                                       if (save_ds1307)
                                        {
                                           rtc_write(0x00,(s%10)+((s/10)<<4));
                                          rtc_write(0x01,(m%10)+((m/10)<<4));
                                           rtc_write(0x02,(h%10)+((h/10)<<4));
                                            save_ds1307              = 0; 
                                        }  
                                         break ;
                                 }
                                       
                                }  
                                     case 3 :
                                      set= 2;
                                 {
                                      {       
                                                       
                                                  while(PINB.3==0)
                                                   delay_ms(100);
                                                 while(PINB.4==0) 
                                         {
                                                  if(PINB.1==0)
                                             {  
                                                   
                                              dat_gio1  =  dat_gio1 ++;
                                                  if ( dat_gio1 >= 24)
                                                  dat_gio1        = 0; 
                                              }
                                              if(PINB.2==0)
                                          {  
                                            
                                          dat_gio1             =  dat_gio1 --;
                                               if ( dat_gio1 <= 0)
                                               dat_gio1         = 23; 
                                          }  
                                         }
                                              while(PIND.4) 
                                            {
                                              lcd_gotoxy(0,0);
                                             _lcd_write_data(0x0F);  
                                             }
                                         break ;      
                                                               
                                     }  
                                      case 4 :
                                       set=3; 
                                   {  
                                                  delay_ms(100);
                                       {
                                                if (PINB.1==0)
                                         {
                                         dat_gio2   = dat_gio2 ++;
                                         if (dat_gio2 >= 24)             
                                         dat_gio2        = 0; 
                                         }
                                                if(PINB.2==0)
                                          {
                                                dat_gio2    = dat_gio2 --;
                                                if (dat_gio2 <= 0)
                                               dat_gio2        = 23; 
                                            }              
                                        }
                                                while(PINB.0) 
                                              {
                                                   lcd_gotoxy(0, 0);
                                                 _lcd_write_data(0x0F);  
                                              };
                                                lcd_gotoxy(0, 0);
                                               _lcd_write_data(0x0C);  
                                     
                                              
                                        }
                                   break ;           
                                  } 
                               }   
                           }                       
                                              hour_wait    = (10*((set_hour>>4)&0x03)+(set_hour&0x0f));
                                              minute_wait  = (10*((set_minute>>4)&0x07)+(set_minute&0x0f));  
                                             if ((dat_gio1<hour_wait<dat_gio2)&(minute_wait<const_datgio));
                                            {
                                                
                                                PINB.5          = 1;
                                            }  
                                               if ((hour_wait<dat_gio1) &( hour_wait> dat_gio2)& (minute_wait>const_datgio))
                                              {
                                                 
                                                 PINB.5         = 0;
                                              }        
                                                       lcd_gotoxy(0, 0);
                                                        lcd_puts("clkreal:");
                                
                                                          lcd_gotoxy(8, 0); 
                                                          lcd_putchar(((set_hour>>4)&0x03)+48);
                                                          lcd_putchar((set_hour&0x0f)+48); 
                               
                                                          lcd_putchar(':');
                                                          lcd_putchar(((set_minute>>4)&0x07)+48);
                                                          lcd_putchar((set_minute&0x0f)+48); 
                                         
                                                          lcd_putchar(':');
                                                          lcd_putchar(((set_seconds>>4)&0x07)+48);
                                                          lcd_putchar((set_seconds&0x0f)+48); 
                                           
                                                          lcd_gotoxy(0, 1);
                                                          lcd_puts("TG BOM:"); 
                                                          lcd_putchar(' ');
                                                          lcd_putchar(dat_gio1/10+48);
                                                          lcd_putchar(dat_gio1%10+48);
                                                          lcd_puts("h-");
                                                          lcd_putchar(dat_gio2/10+48);
                                                          lcd_putchar(dat_gio2%10+48);
                                                          lcd_putchar('h');
                                                          delay_ms(100);  
                                         
                                                        //        time_now                    = 60*set_hour + set_minute;
                                                       //        
                                                     //        lcd_putchar(time_now/1000 + 48);
                                                     //        lcd_putchar((time_now/100)%10 + 48);
                                                    //        lcd_putchar((time_now/10)%10 + 48);
                                                    //        lcd_putchar(time_now%10 + 48); 
                                                    break; 
                                                    
                      }     
                      
    	         case 2 :   
    	                 mode=1;
                         { 
                             if(PINB.0)
                            
                             
     		                {
     			              while(PINB.0==0);
       			              lcd_gotoxy(0, 0);
                              lcd_puts("hen_gio:");                            
    			                                                                                                                                                                                                                                   
                                  donvi=(data/1)%10;
                                   chuc=(data/10)%10;
                                    tram=(data/100)%10;
                                    nghin=(data/1000)%10;
                                    lcd_gotoxy(x,y);
                                    lcd_putchar(nghin+48);
                                    lcd_putchar(tram+48);
                                     lcd_putchar(chuc+48);
                                     lcd_putchar(donvi+48); 
                                    if((set0==1)&&(set1==0))
                                    { 
                                     set++;
                                     if(set>4)
                                     set=0;
                                    }   
                                    switch(set)
                                          {  
                                                {      case 1 :
                                                    set= 1;
                                                  {
                                                    if(PINB.1==0)
                                                     nghin++;
                                                      {if (nghin>9)
                                                       nghin=0; 
                                                     }  
                                                  } 
                                                  }
                                              {   case 2 : 
                                                set=2;
                                                  {
                                                       if(PINB.1==0)
                                                       tram++;
                                                        {
                                                          if(tram>9)
                                                            tram =0;
                                                        }
                                                   }  
                                              } 
                                                { case 3 :
                                                set=3;
                                                  { 
                                                   if(PINB.1==0)
                                                   chuc++;
                                                   {
                                                      if(chuc>9)
                                                      chuc =0;
                                                   }
                                                  }
                                                 } 
                                                  {case 4:
                                                  set=4;
                                                    {
                                                     if(PINB.1==0)
                                                     donvi++;
                                                     {
                                                      if(donvi>9)
                                                      donvi=0;
                                                     }
                                                     }
                                                   
                                                  }       
                                            } 
                                         if(PINB.4==0)
                                         donvi--;
                                         
                                         if(donvi== 0)
                                          {  chuc --;
                                              if(chuc==0) 
                                             {
                                                tram --;
                                                if(tram ==0)
                                               {
                                                 nghin --;
                                               }
                                             }
                                          } 
                                           {
                                                 if (nghin==0,tram==0,chuc==0,donvi==0)
                                               
                                               PINB.5 =1;                                  
                                                
                                           }  
                                            
                              }
    			           } 
                            
                             
                        break ;
               }         
            }    
       }   
       }
    file mô phỏng trên proteus https://www.mediafire.com/?aw2iea5ww6t8yw8
    file hex https://www.mediafire.com/?wndh1t98n0883gz

  • #2
    em ơi, em post cái thư viện LCD của em lên cho anh coi đi. Có thể là do cái thư viện ấy :3

    Comment

    Về tác giả

    Collapse

    minhhien9687 Tìm hiểu thêm về minhhien9687

    Bài viết mới nhất

    Collapse

    Đang tải...
    X