اطلاعیه

Collapse
No announcement yet.

مشکل در نمایش کارکترها در سون سگمنت

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل در نمایش کارکترها در سون سگمنت

    سلام
    من یک برنامه نوشتم که اعداد رو در سون سگمنت نمایش بده اما یک مشکل برام پیش اومده
    اونم اینه که led مربوط به حرف e هم در عدد 5 فعال کردم هم در عدد 6 اما در عدد 5 نشون نمیده اما در عدد 6 نشون میده
    به نظرتون دلیلش چیه ؟غیر منطقی به نظرم میرسه
  • ۱٬۲۱۰٬۰۰۰ ریال ۹۰۷٬۵۰۰ ریال
    ۲۰۸٬۰۰۰ ریال ۱۲۴٬۸۰۰ ریال
    ۸۲٬۰۰۰ ریال ۶۸٬۰۶۰ ریال
    ۶۹٬۹۰۰ ریال ۳۴٬۹۵۰ ریال
    ۱٬۲۶۰٬۰۰۰ ریال ۶۳۰٬۰۰۰ ریال

    #2
    پاسخ : مشکل در نمایش کارکترها در سون سگمنت

    look up table که نوشتی مشکل داره (به احتمال زیاد!)
    برنامه رو بزار!

    دیدگاه


      #3
      پاسخ : مشکل در نمایش کارکترها در سون سگمنت

      کد:
      #define ADC_VREF_TYPE 0x00
       
      // Read the AD conversion result
      unsigned int read_adc(unsigned char adc_input)
      {
      ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
      // Delay needed for the stabilization of the ADC input voltage
      delay_us(10);
      // Start the AD conversion
      ADCSRA|=0x40;
      // Wait for the AD conversion to complete
      while ((ADCSRA & 0x10)==0);
      ADCSRA|=0x10;
      return ADCW;
      }
      
      
      // External Interrupt 0 service routine
      interrupt [EXT_INT0] void ext_int0_isr(void)
      {
      dor++;
      }
      
      // Timer 0 overflow interrupt service routine
      interrupt [TIM0_OVF] void timer0_ovf_isr(void)
      {
      
      lcd_clear();
      lcd_gotoxy(0,0);
      sprintf(lcd,"rpm=%u",dor);
      lcd_puts(lcd);
      delay_ms(50);
      //
      lcd_clear();
      lcd_gotoxy(0,0);
      lcd_putsf("loading");
      delay_ms(100);
      lcd_clear();
       adc0=read_adc(0);
       adc0=adc0/2;
       sprintf(lcd,"T=%u",adc0);
       lcd_puts(lcd);
       delay_ms(100); 
       lcd_clear();
       kd=read_adc(3);
       sprintf(lcd,"kd=%u",kd);
       lcd_puts(lcd);
       delay_ms(100);
       lcd_clear();
       ki=read_adc(2);
       sprintf(lcd,"ki=%u",ki);
       lcd_puts(lcd);
       delay_ms(100);
       lcd_clear();
       kp=read_adc(1);
       sprintf(lcd,"kp=%u",kp);
       lcd_puts(lcd);
       delay_ms(100);
       
       eror=adc0-20;
      if (adc0<25)
      {
      
      OCR1AL=0;
      }
      if(adc0>25)
      {
       uu=eror*20;
      OCR1AL=uu;
       }   
       for (nn=1;nn<=20;nn++)
       {
       yekan=adc0%10;
       dahgan=adc0/10; 
       PORTD.6=0 ;
       PORTD.7=1;
       PORTC=ledfunc[dahgan];
       delay_ms(5);
       PORTD.6=1;
       PORTD.7=0 ;
       PORTC=ledfunc[yekan];
       delay_ms(5); 
        PORTD.6=1;
       PORTD.7=1 ;
       } 
       dor=0;
      }
      
      
      
      void main(void)
      {
      // Declare your local variables 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=0x11110000;
      
      // Port B 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 
      PORTB=0x00;
      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=T State0=T 
      PORTC=0x00;
      DDRC=0xFF;
      
      // Port D 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 
      PORTD=0x00;
      DDRD=0b11100000;
      
      // Timer/Counter 0 initialization
      // Clock source: System Clock
      // Clock value: 7.813 kHz
      // Mode: Normal top=0xFF
      // OC0 output: Disconnected
      TCCR0=0x05;
      TCNT0=0x00;
      OCR0=0x00;
      
      
      // Timer/Counter 1 initialization
      // Clock source: System Clock
      // Clock value: 7.813 kHz
      // Mode: Fast PWM top=0x00FF
      // OC1A output: Non-Inv.
      // 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=0x81;
      TCCR1B=0x0D;
      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: On
      // INT0 Mode: Rising Edge
      // INT1: Off
      // INT2: Off
      GICR|=0x40;
      MCUCR=0x03;
      MCUCSR=0x00;
      GIFR=0x40;
      
      // 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 Clock frequency: 1000.000 kHz
      // ADC Voltage Reference: AREF pin
      ADMUX=ADC_VREF_TYPE & 0xff;
      ADCSRA=0x83;
      
      // SPI initialization
      // SPI disabled
      SPCR=0x00;
      
      // TWI initialization
      // TWI disabled
      TWCR=0x00;
      
      // Alphanumeric LCD initialization
      // Connections specified in the
      // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
      // RS - PORTB Bit 0
      // RD - PORTB Bit 2
      // EN - PORTB Bit 3
      // D4 - PORTB Bit 4
      // D5 - PORTB Bit 5
      // D6 - PORTB Bit 6
      // D7 - PORTB Bit 7
      // Characters/line: 16
      lcd_init(16);
       #asm("sei")
      while (1)
      {
      }  
      }

      دیدگاه


        #4
        پاسخ : مشکل در نمایش کارکترها در سون سگمنت

        مقاومت برای محدود کردن جریان چند اهم باشه؟

        دیدگاه


          #5
          پاسخ : مشکل در نمایش کارکترها در سون سگمنت

          نوشته اصلی توسط masror_d
          کد:
          #define ADC_VREF_TYPE 0x00
           
          // Read the AD conversion result
          unsigned int read_adc(unsigned char adc_input)
          {
          ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
          // Delay needed for the stabilization of the ADC input voltage
          delay_us(10);
          // Start the AD conversion
          ADCSRA|=0x40;
          // Wait for the AD conversion to complete
          while ((ADCSRA & 0x10)==0);
          ADCSRA|=0x10;
          return ADCW;
          }
          
          
          // External Interrupt 0 service routine
          interrupt [EXT_INT0] void ext_int0_isr(void)
          {
          dor++;
          }
          
          // Timer 0 overflow interrupt service routine
          interrupt [TIM0_OVF] void timer0_ovf_isr(void)
          {
          
          lcd_clear();
          lcd_gotoxy(0,0);
          sprintf(lcd,"rpm=%u",dor);
          lcd_puts(lcd);
          delay_ms(50);
          //
          lcd_clear();
          lcd_gotoxy(0,0);
          lcd_putsf("loading");
          delay_ms(100);
          lcd_clear();
           adc0=read_adc(0);
           adc0=adc0/2;
           sprintf(lcd,"T=%u",adc0);
           lcd_puts(lcd);
           delay_ms(100); 
           lcd_clear();
           kd=read_adc(3);
           sprintf(lcd,"kd=%u",kd);
           lcd_puts(lcd);
           delay_ms(100);
           lcd_clear();
           ki=read_adc(2);
           sprintf(lcd,"ki=%u",ki);
           lcd_puts(lcd);
           delay_ms(100);
           lcd_clear();
           kp=read_adc(1);
           sprintf(lcd,"kp=%u",kp);
           lcd_puts(lcd);
           delay_ms(100);
           
           eror=adc0-20;
          if (adc0<25)
          {
          
          OCR1AL=0;
          }
          if(adc0>25)
          {
           uu=eror*20;
          OCR1AL=uu;
           }   
           for (nn=1;nn<=20;nn++)
           {
           yekan=adc0%10;
           dahgan=adc0/10; 
           PORTD.6=0 ;
           PORTD.7=1;
           PORTC=ledfunc[dahgan];
           delay_ms(5);
           PORTD.6=1;
           PORTD.7=0 ;
           PORTC=ledfunc[yekan];
           delay_ms(5); 
            PORTD.6=1;
           PORTD.7=1 ;
           } 
           dor=0;
          }
          
          
          
          void main(void)
          {
          // Declare your local variables 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=0x11110000;
          
          // Port B 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 
          PORTB=0x00;
          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=T State0=T 
          PORTC=0x00;
          DDRC=0xFF;
          
          // Port D 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 
          PORTD=0x00;
          DDRD=0b11100000;
          
          // Timer/Counter 0 initialization
          // Clock source: System Clock
          // Clock value: 7.813 kHz
          // Mode: Normal top=0xFF
          // OC0 output: Disconnected
          TCCR0=0x05;
          TCNT0=0x00;
          OCR0=0x00;
          
          
          // Timer/Counter 1 initialization
          // Clock source: System Clock
          // Clock value: 7.813 kHz
          // Mode: Fast PWM top=0x00FF
          // OC1A output: Non-Inv.
          // 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=0x81;
          TCCR1B=0x0D;
          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: On
          // INT0 Mode: Rising Edge
          // INT1: Off
          // INT2: Off
          GICR|=0x40;
          MCUCR=0x03;
          MCUCSR=0x00;
          GIFR=0x40;
          
          // 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 Clock frequency: 1000.000 kHz
          // ADC Voltage Reference: AREF pin
          ADMUX=ADC_VREF_TYPE & 0xff;
          ADCSRA=0x83;
          
          // SPI initialization
          // SPI disabled
          SPCR=0x00;
          
          // TWI initialization
          // TWI disabled
          TWCR=0x00;
          
          // Alphanumeric LCD initialization
          // Connections specified in the
          // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
          // RS - PORTB Bit 0
          // RD - PORTB Bit 2
          // EN - PORTB Bit 3
          // D4 - PORTB Bit 4
          // D5 - PORTB Bit 5
          // D6 - PORTB Bit 6
          // D7 - PORTB Bit 7
          // Characters/line: 16
          lcd_init(16);
           #asm("sei")
          while (1)
          {
          }  
          }
          مهندس جان برنامه رو کامل گذاشتی؟!
          آخه من هرچی میگردم پیدا نمیکنم []ledfunc رو کجا تعریف کردی و ترتیب تعریفت چه جوریه!

          دیدگاه


            #6
            پاسخ : مشکل در نمایش کارکترها در سون سگمنت

            نوشته اصلی توسط masror_d
            کد:
            #define ADC_VREF_TYPE 0x00
             
            // Read the AD conversion result
            unsigned int read_adc(unsigned char adc_input)
            {
            ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
            // Delay needed for the stabilization of the ADC input voltage
            delay_us(10);
            // Start the AD conversion
            ADCSRA|=0x40;
            // Wait for the AD conversion to complete
            while ((ADCSRA & 0x10)==0);
            ADCSRA|=0x10;
            return ADCW;
            }
            
            
            // External Interrupt 0 service routine
            interrupt [EXT_INT0] void ext_int0_isr(void)
            {
            dor++;
            }
            
            // Timer 0 overflow interrupt service routine
            interrupt [TIM0_OVF] void timer0_ovf_isr(void)
            {
            
            lcd_clear();
            lcd_gotoxy(0,0);
            sprintf(lcd,"rpm=%u",dor);
            lcd_puts(lcd);
            delay_ms(50);
            //
            lcd_clear();
            lcd_gotoxy(0,0);
            lcd_putsf("loading");
            delay_ms(100);
            lcd_clear();
             adc0=read_adc(0);
             adc0=adc0/2;
             sprintf(lcd,"T=%u",adc0);
             lcd_puts(lcd);
             delay_ms(100); 
             lcd_clear();
             kd=read_adc(3);
             sprintf(lcd,"kd=%u",kd);
             lcd_puts(lcd);
             delay_ms(100);
             lcd_clear();
             ki=read_adc(2);
             sprintf(lcd,"ki=%u",ki);
             lcd_puts(lcd);
             delay_ms(100);
             lcd_clear();
             kp=read_adc(1);
             sprintf(lcd,"kp=%u",kp);
             lcd_puts(lcd);
             delay_ms(100);
             
             eror=adc0-20;
            if (adc0<25)
            {
            
            OCR1AL=0;
            }
            if(adc0>25)
            {
             uu=eror*20;
            OCR1AL=uu;
             }   
             for (nn=1;nn<=20;nn++)
             {
             yekan=adc0%10;
             dahgan=adc0/10; 
             PORTD.6=0 ;
             PORTD.7=1;
             PORTC=ledfunc[dahgan];
             delay_ms(5);
             PORTD.6=1;
             PORTD.7=0 ;
             PORTC=ledfunc[yekan];
             delay_ms(5); 
              PORTD.6=1;
             PORTD.7=1 ;
             } 
             dor=0;
            }
            
            
            
            void main(void)
            {
            // Declare your local variables 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=0x11110000;
            
            // Port B 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 
            PORTB=0x00;
            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=T State0=T 
            PORTC=0x00;
            DDRC=0xFF;
            
            // Port D 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 
            PORTD=0x00;
            DDRD=0b11100000;
            
            // Timer/Counter 0 initialization
            // Clock source: System Clock
            // Clock value: 7.813 kHz
            // Mode: Normal top=0xFF
            // OC0 output: Disconnected
            TCCR0=0x05;
            TCNT0=0x00;
            OCR0=0x00;
            
            
            // Timer/Counter 1 initialization
            // Clock source: System Clock
            // Clock value: 7.813 kHz
            // Mode: Fast PWM top=0x00FF
            // OC1A output: Non-Inv.
            // 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=0x81;
            TCCR1B=0x0D;
            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: On
            // INT0 Mode: Rising Edge
            // INT1: Off
            // INT2: Off
            GICR|=0x40;
            MCUCR=0x03;
            MCUCSR=0x00;
            GIFR=0x40;
            
            // 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 Clock frequency: 1000.000 kHz
            // ADC Voltage Reference: AREF pin
            ADMUX=ADC_VREF_TYPE & 0xff;
            ADCSRA=0x83;
            
            // SPI initialization
            // SPI disabled
            SPCR=0x00;
            
            // TWI initialization
            // TWI disabled
            TWCR=0x00;
            
            // Alphanumeric LCD initialization
            // Connections specified in the
            // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
            // RS - PORTB Bit 0
            // RD - PORTB Bit 2
            // EN - PORTB Bit 3
            // D4 - PORTB Bit 4
            // D5 - PORTB Bit 5
            // D6 - PORTB Bit 6
            // D7 - PORTB Bit 7
            // Characters/line: 16
            lcd_init(16);
             #asm("sei")
            while (1)
            {
            }  
            }
            فایل پروژه رو به طور کامل بذارید
            گفت که دیوانه نهی لایق این خانه نهی

            دیدگاه


              #7
              پاسخ : مشکل در نمایش کارکترها در سون سگمنت

              از این برنامه کمک بگیر خیلی راحت کد رو در اختیارتون قرار میده ...
              برنامه رو خودم نوشتم ...
              امیدوارم که خوشتون بیاد
              http://www.eca.ir/forum2/index.php?topic=102119.msg652461#msg652461

              شاد و پیروز باشید
              [b]چگونه همه پایه های میکروکنترلر AVR را PWM کنیم؟
              معرفی نرم افزارEasy 7segment (برای راه اندازی آسانتر 7segment )
              معرفی نرم افزار Codewizard PWM
              با من بیشتر آشنا شوید

              دیدگاه

              لطفا صبر کنید...