ATMEGA16A output pins won't go HIGH

Go To Last Post
40 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone, I have a problem with a project. It is a weekly time I found on the web.

It is originally written for ATMEGA16 but I used the "A" version of this chip.

The problem is that the two output ports (C4 and C5) that are supposed to be HIGH at the preset times, stay LOW!

Could it be because of wrong Fuse Bits? Or the chip is broken? Or maybe the code needs to modified for ATMEGA16A that i'm currently using?

 

I will appreciate any help.

Ciao!

Here is the code:

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 1988/01/01
Author  : 
Company : 
Comments: 


Chip type               : ATmega16
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include <mega16.h>
#include <stdio.h>
                                                    
// I2C Bus functions
#asm
   .equ __i2c_port=0x15 ;PORTC
   .equ __sda_bit=1
   .equ __scl_bit=0
#endasm
#include <i2c.h>

// DS1307 Real Time Clock functions
#include <ds1307.h>

// Alphanumeric LCD Module functions
#include <alcd.h>

#define up      PIND.0
#define down    PIND.1
#define right   PIND.4
#define left    PIND.5
#define ok      PIND.6

#define output1     PORTC.2
#define output2     PORTC.3
#define lcd_light   PORTA.3
                                                                        
unsigned char clear=1,select_screen=15,set=0,count1=0,data[16],num_dsp1,num_dsp2,num_dsp3,num_dsp4;
eeprom unsigned char perm1=0,perm2=0,perm3=0,perm4=0,perm5=0,perm6=0,perm7=0,perm8=0,perm9=0,perm10=0,perm11=0,perm12=0,perm13=0,perm14=0;
unsigned char week_day [8][10]={"         ","  Monday "," Tuesday ","Wednesday"," Thursday","  Friday "," Saturday","  Sunday "};
eeprom char en1=0,en2=0,en3=0,en4=0,en5=0,en6=0,en7=0,en8=0,en9=0,en10=0,en11=0,en12=0,en13=0,en14=0;
unsigned char year,month,day,week,hour,min,sec;
eeprom int hour11=0,min11=0,hour12=0,min12=0,hour13=0,min13=0,hour14=0,min14=0,hour21=0,min21=0,hour22=0,min22=0,hour23=0,min23=0,hour24=0,min24=0,hour31=0,min31=0,hour32=0,min32=0,hour33=0,min33=0,hour34=0,min34=0,hour41=0,min41=0,hour42=0,min42=0,hour43=0,min43=0,hour44=0,min44=0;
eeprom int hour51=0,min51=0,hour52=0,min52=0,hour53=0,min53=0,hour54=0,min54=0,hour61=0,min61=0,hour62=0,min62=0,hour63=0,min63=0,hour64=0,min64=0,hour71=0,min71=0,hour72=0,min72=0,hour73=0,min73=0,hour74=0,min74=0;

void work ()
{
//////////     Monday   /////////////////
    if((hour==hour11)&&(min==min11)&&(perm1==0)&&(en1==1)&&(week==1))
    {
        perm1=1;
        output1=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour12)&&(min==min12)&&(perm1==1)&&(week==1))
    {
        perm1=0;
        output1=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour13)&&(min==min13)&&(perm2==0)&&(en2==1)&&(week==1))
    {
        perm2=1;
        output2=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour14)&&(min==min14)&&(perm2==1)&&(week==1))
    {
        perm2=0;
        output2=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
//////////     Tuesday   /////////////////    
    if((hour==hour21)&&(min==min21)&&(perm3==0)&&(en3==1)&&(week==2))
    {
        perm3=1;
        output1=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour22)&&(min==min22)&&(perm3==1)&&(week==2))
    {
        perm3=0;
        output1=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
    if((hour==hour23)&&(min==min23)&&(perm4==0)&&(en4==1)&&(week==2))
    {
        perm4=1;
        output2=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour24)&&(min==min24)&&(perm4==1)&&(week==2))
    {
        perm4=0;
        output2=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
//////////     wednesday   /////////////////    
    if((hour==hour31)&&(min==min31)&&(perm5==0)&&(en5==1)&&(week==3))
    {
        perm5=1;
        output1=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour32)&&(min==min32)&&(perm5==1)&&(week==3))
    {
        perm5=0;
        output1=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
    if((hour==hour33)&&(min==min33)&&(perm6==0)&&(en6==1)&&(week==3))
    {
        perm6=1;
        output2=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour34)&&(min==min34)&&(perm6==1)&&(week==3))
    {
        perm6=0;
        output2=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
//////////     Thursday   /////////////////    
    if((hour==hour41)&&(min==min41)&&(perm7==0)&&(en7==1)&&(week==4))
    {
        perm7=1;
        output1=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour42)&&(min==min42)&&(perm7==1)&&(week==4))
    {
        perm7=0;
        output1=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
    if((hour==hour43)&&(min==min43)&&(perm8==0)&&(en8==1)&&(week==4))
    {
        perm8=1;
        output2=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour44)&&(min==min44)&&(perm8==1)&&(week==4))
    {
        perm8=0;
        output2=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
//////////     Friday   /////////////////    
    if((hour==hour51)&&(min==min51)&&(perm9==0)&&(en9==1)&&(week==5))
    {
        perm9=1;
        output1=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour52)&&(min==min52)&&(perm9==1)&&(week==5))
    {
        perm9=0;
        output1=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
    if((hour==hour53)&&(min==min53)&&(perm10==0)&&(en10==1)&&(week==5))
    {
        perm10=1;
        output2=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour54)&&(min==min54)&&(perm10==1)&&(week==5))
    {
        perm10=0;
        output2=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
//////////     Saturday   /////////////////    
    if((hour==hour61)&&(min==min61)&&(perm11==0)&&(en11==1)&&(week==6))
    {
        perm11=1;
        output1=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour62)&&(min==min62)&&(perm11==1)&&(week==6))
    {
        perm11=0;
        output1=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
    if((hour==hour63)&&(min==min63)&&(perm12==0)&&(en12==1)&&(week==6))
    {
        perm12=1;
        output2=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour64)&&(min==min64)&&(perm12==1)&&(week==6))
    {
        perm12=0;
        output2=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
//////////     Sunday   /////////////////    
    if((hour==hour71)&&(min==min71)&&(perm13==0)&&(en13==1)&&(week==7))
    {
        perm13=1;
        output1=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour72)&&(min==min72)&&(perm13==1)&&(week==7))
    {
        perm13=0;
        output1=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    
    if((hour==hour73)&&(min==min73)&&(perm14==0)&&(en14==1)&&(week==7))
    {
        perm14=1;
        output2=1;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
    if((hour==hour74)&&(min==min74)&&(perm14==1)&&(week==7))
    {
        perm14=0;
        output2=0;
        
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
    }
}
void show ()
{
    switch(select_screen)
    {
        case 1: lcd_gotoxy(0,0);
                if(en1==0)
                        lcd_putsf(" Mon   No.1:off ");
                if(en1==1)
                        lcd_putsf(" Mon   No.1:on  ");
                num_dsp1=hour11; num_dsp2=min11; num_dsp3=hour12; num_dsp4=min12; break;
        
        case 2: lcd_gotoxy(0,0);
                if(en2==0)
                        lcd_putsf(" Mon   No.2:off ");
                if(en2==1)
                        lcd_putsf(" Mon   No.2:on  ");
                num_dsp1=hour13; num_dsp2=min13; num_dsp3=hour14; num_dsp4=min14; break;
                
        case 3: lcd_gotoxy(0,0);
                if(en3==0)
                        lcd_putsf(" Tue   No.1:off ");
                if(en3==1)
                        lcd_putsf(" Tue   No.1:on  ");
                num_dsp1=hour21; num_dsp2=min21; num_dsp3=hour22; num_dsp4=min22; break;
                
        case 4: lcd_gotoxy(0,0);
                if(en4==0)
                        lcd_putsf(" Tue   No.2:off ");
                if(en4==1)
                        lcd_putsf(" Tue   No.2:on  ");
                num_dsp1=hour23; num_dsp2=min23; num_dsp3=hour24; num_dsp4=min24; break;
        
        case 5: lcd_gotoxy(0,0);
                if(en5==0)
                        lcd_putsf(" Wed   No.1:off ");
                if(en5==1)
                        lcd_putsf(" Wed   No.1:on  ");
                num_dsp1=hour31; num_dsp2=min31; num_dsp3=hour32; num_dsp4=min32; break;
        
        case 6: lcd_gotoxy(0,0);
                if(en6==0)
                        lcd_putsf(" Wed   No.2:off ");
                if(en6==1)
                        lcd_putsf(" Wed   No.2:on  ");
                num_dsp1=hour33; num_dsp2=min33; num_dsp3=hour34; num_dsp4=min34; break;
                
        case 7: lcd_gotoxy(0,0);
                if(en7==0)
                        lcd_putsf(" Thu   No.1:off ");
                if(en7==1)
                        lcd_putsf(" Thu   No.1:on  ");
                num_dsp1=hour41; num_dsp2=min41; num_dsp3=hour42; num_dsp4=min42; break;
                
        case 8: lcd_gotoxy(0,0);
                if(en8==0)
                        lcd_putsf(" Thu   No.2:off ");
                if(en8==1)
                        lcd_putsf(" Thu   No.2:on  ");
                num_dsp1=hour43; num_dsp2=min43; num_dsp3=hour44; num_dsp4=min44; break;
                
        case 9: lcd_gotoxy(0,0);
                if(en9==0)
                        lcd_putsf(" Fri   No.1:off ");
                if(en9==1)
                        lcd_putsf(" Fri   No.1:on  ");
                num_dsp1=hour51; num_dsp2=min51; num_dsp3=hour52; num_dsp4=min52; break;
                
        case 10: lcd_gotoxy(0,0);
                if(en10==0)
                        lcd_putsf(" Fri   No.2:off ");
                if(en10==1)
                        lcd_putsf(" Fri   No.2:on  ");
                num_dsp1=hour53; num_dsp2=min53; num_dsp3=hour54; num_dsp4=min54; break;
                
        case 11: lcd_gotoxy(0,0);
                if(en11==0)
                        lcd_putsf(" Sat   No.1:off ");
                if(en11==1)
                        lcd_putsf(" Sat   No.1:on  ");
                num_dsp1=hour61; num_dsp2=min61; num_dsp3=hour62; num_dsp4=min62; break;
                
        case 12: lcd_gotoxy(0,0);
                if(en12==0)
                        lcd_putsf(" Sat   No.2:off ");
                if(en12==1)
                        lcd_putsf(" Sat   No.2:on  ");
                num_dsp1=hour63; num_dsp2=min63; num_dsp3=hour64; num_dsp4=min64; break;
                
        case 13: lcd_gotoxy(0,0);
                if(en13==0)
                        lcd_putsf(" Sun   No.1:off ");
                if(en13==1)
                        lcd_putsf(" Sun   No.1:on  ");
                num_dsp1=hour71; num_dsp2=min71; num_dsp3=hour72; num_dsp4=min72; break;
                
        case 14: lcd_gotoxy(0,0);
                if(en14==0)
                        lcd_putsf(" Sun   No.2:off ");
                if(en14==1)
                        lcd_putsf(" Sun   No.2:on  ");
                num_dsp1=hour73; num_dsp2=min73; num_dsp3=hour74; num_dsp4=min74; break;
        case 15:
                if(set==0)
                {
                    if(clear==1)
                    {
                        lcd_clear();
                        clear=0;
                    }
                    sprintf(data,"%s",week_day[week]);
                    lcd_gotoxy(3,0);                
                    lcd_puts(data);
                    sprintf(data,"Time is %02d:%02d:%02d",hour,min,sec);
                    lcd_gotoxy(0,1);
                    lcd_puts(data);
                    break;
                }
                if(set==1)
                {
                    sprintf(data,"%s",week_day[week]);
                    lcd_gotoxy(3,0);
                    lcd_puts(data);
                    lcd_gotoxy(0,1);
                    lcd_putsf("Time is --:--:--"); clear=1; break;
                }
                if(set==2)
                {
                    if(clear==1)
                    {
                        lcd_clear();
                        clear=0;
                    }
                    lcd_gotoxy(0,0);
                    lcd_putsf("   ----------   ");
                    sprintf(data,"Time is %02d:--:--",hour);
                    lcd_gotoxy(0,1);
                    lcd_puts(data);
                    break;
                }
                if(set==3)
                {
                    lcd_gotoxy(0,0);
                    lcd_putsf("   ----------   ");                                      
                    sprintf(data,"Time is --:%02d:--",min);
                    lcd_gotoxy(0,1);
                    lcd_puts(data);
                    break;
                }
                if(set==4)
                {
                    lcd_gotoxy(0,0);
                    lcd_putsf("   ----------   ");
                    sprintf(data,"Time is --:--:%02d",sec);
                    lcd_gotoxy(0,1);
                    lcd_puts(data);
                    clear=1; break;
                }
    }
    if(select_screen<15)
    {
        if(set==0)
        {
            sprintf(data,"%02d:%02d  to  %02d:%02d",num_dsp1,num_dsp2,num_dsp3,num_dsp4);
            lcd_gotoxy(0,1); lcd_puts(data);
        }
        if(set==1)
        {
            sprintf(data,"%02d:--  to  --:--",num_dsp1);
            lcd_gotoxy(0,1); lcd_puts(data);
        }
        if(set==2)
        {
            sprintf(data,"--:%02d  to  --:--",num_dsp2);
            lcd_gotoxy(0,1); lcd_puts(data);
        }
        if(set==3)
        {
            sprintf(data,"--:--  to  %02d:--",num_dsp3);
            lcd_gotoxy(0,1); lcd_puts(data);
        }
        if(set==4)
        {
            sprintf(data,"--:--  to  --:%02d",num_dsp4);
            lcd_gotoxy(0,1); lcd_puts(data);
        }
    }
}
void keypad()
{
    if(up==0)
    {
        if(lcd_light==0)
        {
            lcd_light=1;
            TCCR1B=0x03;
            count1=0;
            goto end1;
        }
        count1=0;
        switch(select_screen)
        {
            case 1: if(set==0)
                    {
                        en1=1;
                    }
                    if(set==1)
                    {
                        hour11++;
                        if(hour11>23)
                            hour11=0;
                    }
                    if(set==2)
                    {
                        min11++;
                        if(min11>59)
                            min11=0;
                    }
                    if(set==3)
                    {
                        hour12++;
                        if(hour12>23)
                            hour12=0;
                    }
                    if(set==4)
                    {
                        min12++;
                        if(min12>59)
                            min12=0;
                    }
                    break;
            
            case 2: if(set==0)
                    {
                        en2=1;
                    }
                    if(set==1)
                    {
                        hour13++;
                        if(hour13>23)
                            hour13=0;
                    }
                    if(set==2)
                    {
                        min13++;
                        if(min13>59)
                            min13=0;
                    }
                    if(set==3)
                    {
                        hour14++;
                        if(hour14>23)
                            hour14=0;
                    }
                    if(set==4)
                    {
                        min14++;
                        if(min14>59)
                            min14=0;
                    }
                    break;
                    
             case 3: if(set==0)
                    {
                        en3=1;
                    }
                    if(set==1)
                    {
                        hour21++;
                        if(hour21>23)
                            hour21=0;
                    }
                    if(set==2)
                    {
                        min21++;
                        if(min21>59)
                            min21=0;
                    }
                    if(set==3)
                    {
                        hour22++;
                        if(hour22>23)
                            hour22=0;
                    }
                    if(set==4)
                    {
                        min22++;
                        if(min22>59)
                            min22=0;
                    }
                    break;
                    
             case 4: if(set==0)
                    {
                        en4=1;
                    }
                    if(set==1)
                    {
                        hour23++;
                        if(hour23>23)
                            hour23=0;
                    }
                    if(set==2)
                    {
                        min23++;
                        if(min23>59)
                            min23=0;
                    }
                    if(set==3)
                    {
                        hour24++;
                        if(hour24>23)
                            hour24=0;
                    }
                    if(set==4)
                    {
                        min24++;
                        if(min24>59)
                            min24=0;
                    }
                    break;
                    
            case 5: if(set==0)
                    {
                        en5=1;
                    }
                    if(set==1)
                    {
                        hour31++;
                        if(hour31>23)
                            hour31=0;
                    }
                    if(set==2)
                    {
                        min31++;
                        if(min31>59)
                            min31=0;
                    }
                    if(set==3)
                    {
                        hour32++;
                        if(hour32>23)
                            hour32=0;
                    }
                    if(set==4)
                    {
                        min32++;
                        if(min32>59)
                            min32=0;
                    }
                    break;
                    
            case 6: if(set==0)
                    {
                        en6=1;
                    }
                    if(set==1)
                    {
                        hour33++;
                        if(hour33>23)
                            hour33=0;
                    }
                    if(set==2)
                    {
                        min33++;
                        if(min33>59)
                            min33=0;
                    }
                    if(set==3)
                    {
                        hour34++;
                        if(hour34>23)
                            hour34=0;
                    }
                    if(set==4)
                    {
                        min34++;
                        if(min34>59)
                            min34=0;
                    }
                    break;
                    
             case 7: if(set==0)
                    {
                        en7=1;
                    }
                    if(set==1)
                    {
                        hour41++;
                        if(hour41>23)
                            hour41=0;
                    }
                    if(set==2)
                    {
                        min41++;
                        if(min41>59)
                            min41=0;
                    }
                    if(set==3)
                    {
                        hour42++;
                        if(hour42>23)
                            hour42=0;
                    }
                    if(set==4)
                    {
                        min42++;
                        if(min42>59)
                            min42=0;
                    }
                    break;
                    
             case 8: if(set==0)
                    {
                        en8=1;
                    }
                    if(set==1)
                    {
                        hour43++;
                        if(hour43>23)
                            hour43=0;
                    }
                    if(set==2)
                    {
                        min43++;
                        if(min43>59)
                            min43=0;
                    }
                    if(set==3)
                    {
                        hour44++;
                        if(hour44>23)
                            hour44=0;
                    }
                    if(set==4)
                    {
                        min44++;
                        if(min44>59)
                            min44=0;
                    }
                    break;
                    
             case 9: if(set==0)
                    {
                        en9=1;
                    }
                    if(set==1)
                    {
                        hour51++;
                        if(hour51>23)
                            hour51=0;
                    }
                    if(set==2)
                    {
                        min51++;
                        if(min51>59)
                            min51=0;
                    }
                    if(set==3)
                    {
                        hour52++;
                        if(hour52>23)
                            hour52=0;
                    }
                    if(set==4)
                    {
                        min52++;
                        if(min52>59)
                            min52=0;
                    }
                    break;
                    
             case 10: if(set==0)
                    {
                        en10=1;
                    }
                    if(set==1)
                    {
                        hour53++;
                        if(hour53>23)
                            hour53=0;
                    }
                    if(set==2)
                    {
                        min53++;
                        if(min53>59)
                            min53=0;
                    }
                    if(set==3)
                    {
                        hour54++;
                        if(hour54>23)
                            hour54=0;
                    }
                    if(set==4)
                    {
                        min54++;
                        if(min54>59)
                            min54=0;
                    }
                    break;
                    
             case 11: if(set==0)
                    {
                        en11=1;
                    }
                    if(set==1)
                    {
                        hour61++;
                        if(hour61>23)
                            hour61=0;
                    }
                    if(set==2)
                    {
                        min61++;
                        if(min61>59)
                            min61=0;
                    }
                    if(set==3)
                    {
                        hour62++;
                        if(hour62>23)
                            hour62=0;
                    }
                    if(set==4)
                    {
                        min62++;
                        if(min62>59)
                            min62=0;
                    }
                    break;
                    
             case 12: if(set==0)
                    {
                        en12=1;
                    }
                    if(set==1)
                    {
                        hour63++;
                        if(hour63>23)
                            hour63=0;
                    }
                    if(set==2)
                    {
                        min63++;
                        if(min63>59)
                            min63=0;
                    }
                    if(set==3)
                    {
                        hour64++;
                        if(hour64>23)
                            hour64=0;
                    }
                    if(set==4)
                    {
                        min64++;
                        if(min64>59)
                            min64=0;
                    }
                    break;
                    
             case 13: if(set==0)
                    {
                        en13=1;
                    }
                    if(set==1)
                    {
                        hour71++;
                        if(hour71>23)
                            hour71=0;
                    }
                    if(set==2)
                    {
                        min71++;
                        if(min71>59)
                            min71=0;
                    }
                    if(set==3)
                    {
                        hour72++;
                        if(hour72>23)
                            hour72=0;
                    }
                    if(set==4)
                    {
                        min72++;
                        if(min72>59)
                            min72=0;
                    }
                    break;
                    
             case 14: if(set==0)
                    {
                        en14=1;
                    }
                    if(set==1)
                    {
                        hour73++;
                        if(hour73>23)
                            hour73=0;
                    }
                    if(set==2)
                    {
                        min73++;
                        if(min73>59)
                            min73=0;
                    }
                    if(set==3)
                    {
                        hour74++;
                        if(hour74>23)
                            hour74=0;
                    }
                    if(set==4)
                    {
                        min74++;
                        if(min74>59)
                            min74=0;
                    }
                    break;
                    
             case 15: if(set==1)
                    {
                        week++;
                        lcd_clear();
                        if(week>7)
                            week=1;
                        rtc_set_date(week,day,month,year);
                    }
                    if(set==2)
                    {
                        hour++;
                        if(hour>23)
                            hour=0;
                        rtc_set_time(hour,min,sec);
                    }
                    if(set==3)
                    {
                        min++;
                        if(min>59)
                            min=0;
                        rtc_set_time(hour,min,sec);
                    }
                    if(set==4)
                    {
                        sec++;
                        if(sec>59)
                            sec=0;
                        rtc_set_time(hour,min,sec);
                    }
                    break;
        }
        end1:
        while(!up);
    }
    if(down==0)
    {
        if(lcd_light==0)
        {
            lcd_light=1;
            TCCR1B=0x03;
            count1=0;
            goto end2;
        }
        count1=0;
        switch(select_screen)
        {
            case 1: if(set==0)
                    {
                        en1=0;
                    }
                    if(set==1)
                    {
                        hour11--;
                        if(hour11<0)
                            hour11=23;
                    }
                    if(set==2)
                    {
                        min11--;
                        if(min11<0)
                            min11=59;
                    }
                    if(set==3)
                    {
                        hour12--;
                        if(hour12<0)
                            hour12=23;
                    }
                    if(set==4)
                    {
                        min12--;
                        if(min12<0)
                            min12=59;
                    }
                    break;
            
            case 2: if(set==0)
                    {
                        en2=0;
                    }
                    if(set==1)
                    {
                        hour13--;
                        if(hour13<0)
                            hour13=23;
                    }
                    if(set==2)
                    {
                        min13--;
                        if(min13<0)
                            min13=59;
                    }
                    if(set==3)
                    {
                        hour14--;
                        if(hour14<0)
                            hour14=23;
                    }
                    if(set==4)
                    {
                        min14--;
                        if(min14<0)
                            min14=59;
                    }
                    break;
                    
             case 3:if(set==0)
                    {
                        en3=0;
                    }
                    if(set==1)
                    {
                        hour21--;
                        if(hour21<0)
                            hour21=23;
                    }
                    if(set==2)
                    {
                        min21--;
                        if(min21<0)
                            min21=59;
                    }
                    if(set==3)
                    {
                        hour22--;
                        if(hour22<0)
                            hour22=23;
                    }
                    if(set==4)
                    {
                        min22--;
                        if(min22<0)
                            min22=59;
                    }
                    break;
                    
             case 4: if(set==0)
                    {
                        en4=0;
                    }
                    if(set==1)
                    {
                        hour23--;
                        if(hour23<0)
                            hour23=23;
                    }
                    if(set==2)
                    {
                        min23--;
                        if(min23<0)
                            min23=59;
                    }
                    if(set==3)
                    {
                        hour24--;
                        if(hour24<0)
                            hour24=23;
                    }
                    if(set==4)
                    {
                        min24--;
                        if(min24<0)
                            min24=59;
                    }
                    break;
                    
            case 5: if(set==0)
                    {
                        en5=0;
                    }
                    if(set==1)
                    {
                        hour31--;
                        if(hour31<0)
                            hour31=23;
                    }
                    if(set==2)
                    {
                        min31--;
                        if(min31<0)
                            min31=59;
                    }
                    if(set==3)
                    {
                        hour32--;
                        if(hour32<0)
                            hour32=23;
                    }
                    if(set==4)
                    {
                        min32--;
                        if(min32<0)
                            min32=59;
                    }
                    break;
                    
            case 6: if(set==0)
                    {
                        en6=0;
                    }
                    if(set==1)
                    {
                        hour33--;
                        if(hour33<0)
                            hour33=23;
                    }
                    if(set==2)
                    {
                        min33--;
                        if(min33<0)
                            min33=59;
                    }
                    if(set==3)
                    {
                        hour34--;
                        if(hour34<0)
                            hour34=23;
                    }
                    if(set==4)
                    {
                        min34--;
                        if(min34<0)
                            min34=59;
                    }
                    break;
                    
             case 7: if(set==0)
                    {
                        en7=0;
                    }
                    if(set==1)
                    {
                        hour41--;
                        if(hour41<0)
                            hour41=23;
                    }
                    if(set==2)
                    {
                        min41--;
                        if(min41<0)
                            min41=59;
                    }
                    if(set==3)
                    {
                        hour42--;
                        if(hour42<0)
                            hour42=23;
                    }
                    if(set==4)
                    {
                        min42--;
                        if(min42<0)
                            min42=59;
                    }
                    break;
                    
             case 8: if(set==0)
                    {
                        en8=0;
                    }
                    if(set==1)
                    {
                        hour43--;
                        if(hour43<0)
                            hour43=23;
                    }
                    if(set==2)
                    {
                        min43--;
                        if(min43<0)
                            min43=59;
                    }
                    if(set==3)
                    {
                        hour44--;
                        if(hour44<0)
                            hour44=23;
                    }
                    if(set==4)
                    {
                        min44--;
                        if(min44<0)
                            min44=59;
                    }
                    break;
                    
             case 9: if(set==0)
                    {
                        en9=0;
                    }
                    if(set==1)
                    {
                        hour51--;
                        if(hour51<0)
                            hour51=23;
                    }
                    if(set==2)
                    {
                        min51--;
                        if(min51<0)
                            min51=59;
                    }
                    if(set==3)
                    {
                        hour52--;
                        if(hour52<0)
                            hour52=23;
                    }
                    if(set==4)
                    {
                        min52--;
                        if(min52<0)
                            min52=59;
                    }
                    break;
                    
             case 10: if(set==0)
                    {
                        en10=0;
                    }
                    if(set==1)
                    {
                        hour53--;
                        if(hour53<0)
                            hour53=23;
                    }
                    if(set==2)
                    {
                        min53--;
                        if(min53<0)
                            min53=59;
                    }
                    if(set==3)
                    {
                        hour54--;
                        if(hour54<0)
                            hour54=23;
                    }
                    if(set==4)
                    {
                        min54--;
                        if(min54<0)
                            min54=59;
                    }
                    break;
                    
             case 11: if(set==0)
                    {
                        en11=0;
                    }
                    if(set==1)
                    {
                        hour61--;
                        if(hour61<0)
                            hour61=23;
                    }
                    if(set==2)
                    {
                        min61--;
                        if(min61<0)
                            min61=59;
                    }
                    if(set==3)
                    {
                        hour62--;
                        if(hour62<0)
                            hour62=23;
                    }
                    if(set==4)
                    {
                        min62--;
                        if(min62<0)
                            min62=59;
                    }
                    break;
                    
             case 12: if(set==0)
                    {
                        en12=0;
                    }
                    if(set==1)
                    {
                        hour63--;
                        if(hour63<0)
                            hour63=23;
                    }
                    if(set==2)
                    {
                        min63--;
                        if(min63<0)
                            min63=59;
                    }
                    if(set==3)
                    {
                        hour64--;
                        if(hour64<0)
                            hour64=23;
                    }
                    if(set==4)
                    {
                        min64--;
                        if(min64<0)
                            min64=59;
                    }
                    break;
                    
             case 13: if(set==0)
                    {
                        en13=0;
                    }
                    if(set==1)
                    {
                        hour71--;
                        if(hour71<0)
                            hour71=23;
                    }
                    if(set==2)
                    {
                        min71--;
                        if(min71<0)
                            min71=59;
                    }
                    if(set==3)
                    {
                        hour72--;
                        if(hour72<0)
                            hour72=23;
                    }
                    if(set==4)
                    {
                        min72--;
                        if(min72<0)
                            min72=59;
                    }
                    break;
                    
             case 14: if(set==0)
                    {
                        en14=0;
                    }
                    if(set==1)
                    {
                        hour73--;
                        if(hour73<0)
                            hour73=23;
                    }
                    if(set==2)
                    {
                        min73--;
                        if(min73<0)
                            min73=59;
                    }
                    if(set==3)
                    {
                        hour74--;
                        if(hour74<0)
                            hour74=23;
                    }
                    if(set==4)
                    {
                        min74--;
                        if(min74<0)
                            min74=59;
                    }
                    break;
                    
             case 15: if(set==1)
                    {
                        week--;
                        lcd_clear();
                        if(week<1)
                            week=7;
                        rtc_set_date(week,day,month,year);
                    }
                    if(set==2)
                    {
                        if(hour==0)
                        {
                            hour=23;
                            goto lable1;
                        }
                        if(hour>0)
                            hour--;
                        lable1:
                        rtc_set_time(hour,min,sec);
                    }
                    if(set==3)
                    {
                        if(min==0)
                        {
                            min=59;
                            goto lable2;
                        }
                        if(min>0)
                            min--;
                        lable2:
                        rtc_set_time(hour,min,sec);
                    }
                    if(set==4)
                    {
                        if(sec==0)
                        {
                            sec=59;
                            goto lable3;
                        }
                        if(sec>0)
                            sec--;
                        lable3:
                        rtc_set_time(hour,min,sec);
                    }
                    break;
        }
        end2:
        while(!down);
    }
    if(right==0)
    {
        if(lcd_light==0)
        {
            lcd_light=1;
            TCCR1B=0x03;
            count1=0;
            goto end3;
        }
        count1=0;
        select_screen++;
        lcd_clear();
        set=0;
        if(select_screen>15)
            select_screen=1;
        end3:
        while(!right);
    }
    if(left==0)
    {
        if(lcd_light==0)
        {
            lcd_light=1;
            TCCR1B=0x03;
            count1=0;
            goto end4;
        }
        count1=0;
        select_screen--;
        lcd_clear();
        set=0;
        if(select_screen<1)
            select_screen=15;
        end4:
        while(!left);
    }
    if(ok==0)
    {
        if(lcd_light==0)
        {
            lcd_light=1;
            TCCR1B=0x03;
            count1=0;
            goto end5;
        }
        switch(select_screen)
        {
            case 1:  en1=0; break;
            case 2:  en2=0; break;
            case 3:  en3=0; break;
            case 4:  en4=0; break;
            case 5:  en5=0; break;
            case 6:  en6=0; break;
            case 7:  en7=0; break;
            case 8:  en8=0; break;
            case 9:  en9=0; break;
            case 10: en10=0; break;
            case 11: en11=0; break;
            case 12: en12=0; break;
            case 13: en13=0; break;
            case 14: en14=0; break;
        }
        count1=0;
        set++;
        if(set>4)
            set=0;
        end5:
        while(!ok);
    }
}

// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
    //Reset All EEPROM
    if(lcd_light==0)
    {
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
        goto end6;
    }
    count1=0;
    
    hour11=0;
    min11=0;
    hour12=0;
    min12=0;
    hour13=0;
    min13=0;
    hour14=0;
    min14=0;
    hour21=0;
    min21=0;
    hour22=0;
    min22=0;
    hour23=0;
    min23=0;
    hour24=0;
    min24=0;
    hour31=0;
    min31=0;
    hour32=0;
    min32=0;
    hour33=0;
    min33=0;
    hour34=0;
    min34=0;
    hour41=0;
    min41=0;
    hour42=0;
    min42=0;
    hour43=0;
    min43=0;
    hour44=0;
    min44=0;

    hour51=0;
    min51=0;
    hour52=0;
    min52=0;
    hour53=0;
    min53=0;
    hour54=0;
    min54=0;
    hour61=0;
    min61=0;
    hour62=0;
    min62=0;
    hour63=0;
    min63=0;
    hour64=0;
    min64=0;
    hour71=0;
    min71=0;
    hour72=0;
    min72=0;
    hour73=0;
    min73=0;
    hour74=0;
    min74=0;
    
    lcd_clear();
    show();
    
    end6:
}

// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
// Place your code here
    if(lcd_light==0)
    {
        lcd_light=1;
        TCCR1B=0x03;
        count1=0;
        goto end7;
    }
    count1=0;
    
    //Reset this screen EEPROM
    switch(select_screen)
    {
        case 1:  hour11=0; min11=0; hour12=0; min12=0; break;
        case 2:  hour13=0; min13=0; hour14=0; min14=0; break;
        case 3:  hour21=0; min21=0; hour22=0; min22=0; break;
        case 4:  hour23=0; min23=0; hour24=0; min24=0; break;
        case 5:  hour31=0; min31=0; hour32=0; min32=0; break;
        case 6:  hour33=0; min33=0; hour34=0; min34=0; break;
        case 7:  hour41=0; min41=0; hour42=0; min42=0; break;
        case 8:  hour43=0; min43=0; hour44=0; min44=0; break;
        case 9:  hour51=0; min51=0; hour52=0; min52=0; break;
        case 10: hour53=0; min53=0; hour54=0; min54=0; break;
        case 11: hour61=0; min61=0; hour62=0; min62=0; break;
        case 12: hour63=0; min63=0; hour64=0; min64=0; break;
        case 13: hour71=0; min71=0; hour72=0; min72=0; break;
        case 14: hour73=0; min73=0; hour74=0; min74=0; break;
        case 15: 
            week=1; hour=0; min=0; sec=0;
            rtc_set_time(hour,min,sec);
            rtc_set_date(week,day,month,year);
            lcd_clear(); show();
            break;
    }
    end7:
}

// External Interrupt 2 service routine
interrupt [EXT_INT2] void ext_int2_isr(void)
{
// Place your code here
    
}

// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
TCNT0=0x05;
// Place your code here
    
}

// Timer1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Place your code here
    count1++;
    if(count1>20)
    {
        count1=0;
        TCCR1B=0x00;
        lcd_light=0;
    }
}

// Timer2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
// Place your code here

}

// Declare your global variables here

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=0x08;

// 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=0x30;

// 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=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 31.250 kHz
// Mode: Normal top=0xFF
// OC0 output: Disconnected
//TCCR0=0x04;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 125.000 kHz
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
//TCCR1B=0x03;
TCCR1B=0x00;
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: 125.000 kHz
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
//TCCR2=0x04;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: On
// INT1 Mode: Falling Edge
// INT2: On
// INT2 Mode: Falling Edge
GICR|=0xE0;
MCUCR=0x0A;
MCUCSR=0x00;
GIFR=0xE0;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x45;

// 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_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 specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 2
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);

// Global enable interrupts
#asm("sei")
lcd_light=1;
TCCR1B=0x03;
count1=0;
while (1)
      {
      // Place your code here
        keypad();
        work();
        rtc_get_time(&hour,&min,&sec);
        rtc_get_date(&week,&day,&month,&year);
        show();
      }
}

 

This topic has a solution.
Last Edited: Fri. Sep 14, 2018 - 04:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's an awfully big posted program to wade through.  Line 47 is my guess.  Have you reduced to a small "sanity check" program and seen if the symptoms remained?  If not...

 

Anyway, is it "wrong fuse bits"?  How do the fuse bits compare with those on your Mega16 version?

 

All that said, what are the alternate functions of those port C bits?  JTAG, right?  What is the default value?  Did you disable it with fuse setting or code sequence?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm sorry for my big post. I thought maybe users need to see the whole code. 

I changed the ports to see if they behave equally. Originally it was like this:

#define output1     PORTC.4
#define output2     PORTC.5

Non of them works!

I disabled the Jtag Fuse but it didn't help.

Thank you for your attention.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define output1     PORTC.2
#define output2     PORTC.3
..
DDRC=0x30;

In the shown code the chosen pins are not configured as outputs.

 

Though I can't tell you anything about this:

kooroshi60 wrote:
I changed the ports to see if they behave equally. Originally it was like this: #define output1 PORTC.4 #define output2 PORTC.5 Non of them works!

 

 

 

 

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kooroshi60 wrote:
I disabled the Jtag Fuse but it didn't help.

I find that hard to believe, if indeed the "pins won't go high" and it is PC4 and PC5 and they are made outputs.

 

Create a small test program that demonstrates your symptoms.  Show schematic and connections.  Tell how you are testing.  Tell what you expect to happen, and what >>is<< happening.  Tell toolchain, version, and optimization settings.  Tell AVR clock speed, and supply voltage level.  If still confusing after you work through that, post the generated code from the compiler.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"In posted code", C2 and C3 do not work. It is because DDRC is not changed at 0x30.

Please check the operation of C4 and C5 with minimum code.
Nobody knows whether the fuse setting is normal or not. Even words of your "disabled" also.

Last Edited: Tue. Sep 11, 2018 - 03:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
I find that hard to believe,
+1

 

Whenever there's an "issue" with PC4..7 on a JTAG chip like mega16 isn't it always the JTAGEN ??

 

Assuming the change of fuse has failed simply try:

void main(void)
{
    MCUCR = (1 << JTD);
    MCUCR = (1 << JTD);
// Declare your local variables here

I'd be astonished if that didn't fix it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Whenever there's an "issue" with PC4..7 on a JTAG chip like mega16 isn't it always the JTAGEN ??

Sometimes.  ;)  But this family is PC2/3/4/5

...which is why changing to PC2 and PC3 doesn't help much if our premise is correct.

 

While your posted disable sequence would generally work in the WYSIWYG world of CodeVision, for real work  one should bracket the sequence with appropriate incantations.

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've often wondered why AVR Libc didn't have something to handle disabling JTAG.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've often wondered why anyone would want to disable their debug access to the chip.

 

Do they like making life difficult for themselves?

 

Do they also turn out the lights, and try to solder purely by sense of touch?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
I've often wondered why anyone would want to disable their debug access to the chip.

To each his own, I guess.  Since 2000 we've had scores and scores of production AVR8 designs.  None of them has JTAG enabled.  (I guess that might be about half of the apps as a number are Mega8-family of various generations, and some Tinys.)

 

In thinking about that and your wonderment, one factor is certainly that a group of four pins "is a terrible thing to waste".

 

[edit]  Edited to be more Grammatically correct.

 

The kicks of Martín Gramática were usually correct -- does that count?

Image result for Martín Gramática

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Tue. Sep 11, 2018 - 07:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
four pins "is a terrible thing to waste (sic)".

Yes - and that's the driver behind all the various reduced pin count options we see today

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sic? ???  I've been accused of that, I guess.

 

It is phrased in that tense as it is part of a well-known saying some years back [at least] here in the colonies: 

https://www.npr.org/sections/cod...

A Mind Is A Terrible Thing To Waste

So I'll edit to make it more grammatically correct.  But I still have a purpose for each thing I asked the OP for.   The seeming stream of requests are part of the analysis process that I [at least] would use when a puzzling turn of events happens.  And the first is a small sanity-check program and attendant items.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"sic" as in whether it actually constitutes a "waste" ...

 

But we digress.

 

theusch wrote:
The seeming stream of requests are part of the analysis process that I [at least] would use when a puzzling turn of events happens.

The biggest lack in so many posts seen here seems to be a total lack of any idea of how to analyse a problem, and work towards a solution.

 

frown

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If everyone had these skills, then I’d be out of a job! It could be a generational thing - before the interwebs there was no easy means to ask questions unless you moved in a social circle where there were skilled people.
University (hopefully) equips you with the theory and tools to solve a problem. This seems to be less likely these days.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you guys for your help. Let me sum up everything about my project and make things clear.

This is the schematic of the timer:

  

This is the full article:

http://www.plcgoods.net/article_info.php/articles_id/44

 

The code is written for ATMEGA16 but I couldn't find this chip so I used the newer version (ATMEGA16A)

In migration notes of this new "A version" chip is written that it is a drop-in replacement for the older chip.

I tried burning the code using a universal programmer (TOP2009) and my handmade AVRISP MK2 several times.

Clock, buttons and LCD work flawlessly. The only flaw is that, none of the output pins go High when they are supposed to.

So I started thinking there should be a problem with the FUSE Bits. I started playing around with them using online FUSE Bit calculators and I saw that code started behaving differently but still not the way it should.

Well, it was not a good idea to change the Fuse Bits because I damaged a chip doing this.

 

My current Fuse Bits are like this:

Internal oscillator

CKSEL0 = 0

CKSEL1 = 0

CKSEL2 = 1

CKSEL3 = 0

 

SUT0 = Enable

SUT1 = Disable

BODEN = Disable

BODLEVEL = Disable

BOOTRST = Disable

BOOTSZ0 = Enable

BOOTSZ1 = Enable

EESAVE = Disable

CKOPT = Disable

SPIEN = Enable

JTAGEN = Disable

OCDEN = Disable

 

Here is a part of the code in which the ports are defined:

#include <mega16.h>
#include <stdio.h>
                                                    
// I2C Bus functions
#asm
   .equ __i2c_port=0x15 ;PORTC
   .equ __sda_bit=1
   .equ __scl_bit=0
#endasm
#include <i2c.h>

// DS1307 Real Time Clock functions
#include <ds1307.h>

// Alphanumeric LCD Module functions
#include <alcd.h>

#define up      PIND.0
#define down    PIND.1
#define right   PIND.4
#define left    PIND.5
#define ok      PIND.6

#define output1     PORTC.4
#define output2     PORTC.5
#define lcd_light   PORTA.3
                                                                        
void work ()
{
]

void main(void)
{
PORTA=0x00;
DDRA=0x08;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x30;
PORTD=0x00;
DDRD=0x00;

This is all I know so far about it. I have already spent so much time on this. Designed a nice PCB and rain detection relay! So I really don't want to leave this problem unsolved.

I really appreciate your attention and kind responses.

Ciao!

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is C1 really 100pf????

 

PC5 and PC6 default to JTAG mode unless you turn it off in code or by fuse. (you say it's turned off but double check by reading the fuses)

 

AVCC MUST BE CONNECTED TO VCC!

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

Is C1 really 100pf????

 

PC5 and PC6 default to JTAG mode unless you turn it off in code or by fuse. (you say it's turned off but double check by reading the fuses)

 

AVCC MUST BE CONNECTED TO VCC!

I believe it is a typing mistake. I put a 100nf instead.

I double checked the Fuse Bits in AVR Studio 6.2. JTAGEN was disabled. Do I need to disabled it in the code too?

AVCC  is now connected to VCC but problem still remains.

It's so weird and frustrating because every thing looks just fine. 

I'll try to find an ATMEGA16 and see if it behaves like the "A" version.

Thank you so much for your suggestions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I double checked the Fuse Bits in AVR Studio 6.2. JTAGEN was disabled.

Is not that I don't trust you  cheeky but can you please show us a screen shot of the fuses pages from AS6?

 

edit also I see that originally you had

#define output1     PORTC.2
#define output2     PORTC.3

and not PORTC4 and 5, you seem to have changed that.

 

As you have LEDs on both pins you could just write some simple code to alternatively turn the LEDs on and off.

 

If you have a JTAG then it is even simpler, put a breakpoint in your code after the init, check that the ports are actually set for output and then manually turn the pins on and off.

 

Of course I hope you have checked for shorts to ground on those pins.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Thu. Sep 13, 2018 - 03:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would connect Pin-31 to GND and test again.

It's almost universal these days, whichever Micro vendor you choose. Power pins come in (usually adjacent) pairs. All pairs MUST be connected and decoupled (with 100nF ceramic) for proper operation. So in your circuit; Pin-10/11 and Pin-30/31 require these connections.

 

I'm also struggling to find your programming port.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hmmm missed pin 31. sad

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I connected the AVCC to VCC, added another 100n capacitor and connected Pin31(gnd) to the ground. 

Problem is still there.

But I noticed that when the Chip is ON, PC4 and PC5 are pulled down all the time regardless of timer ON/OFF condition.

The resistance between these two pins and GND is 30 ohms. 

I removed the chip and checked if PCB was short but it was OK.

Any idea?

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kooroshi60 wrote:
Any idea?
It's JTAG. Suggest you turn it off.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a screen shot of my Fuse settings in Atmel Studio

I have disabled the JTAGEN. I'll disable it in the code too.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it possible to use another port? Say portB

or using PC2 and PC3 of portC?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I couldn't read your code from the posting (all green really hinders readability, but that's not your fault) so I copied & pasted your code into Visual Studio Code to get some colouring and I still couldn't make anything of it.

 

Anyway what I could glean is that you set PORTC.4 & PORTC.5 as output low in main() and those pins are not touched ever again.

You reported that your AVR is driving those pins low. I would say that your mega16A is working correctly and doing exactly what you've programmed.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

N.Winterbottom wrote:

OK, I couldn't read your code from the posting (all green really hinders readability, but that's not your fault) so I copied & pasted your code into Visual Studio Code to get some colouring and I still couldn't make anything of it.

 

Anyway what I could glean is that you set PORTC.4 & PORTC.5 as output low in main() and those pins are not touched ever again.

You reported that your AVR is driving those pins low. I would say that your mega16A is working correctly and doing exactly what you've programmed.

 

 

Thank you so much for your attention and patience. That is a small part of the code I have posted to  show the ports initialization.

The whole thing is too long to post here. 

Here is the link to the complete code:

https://www.dropbox.com/s/2iady6...

  

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

theusch wrote:
I find that hard to believe,
+1

 

Whenever there's an "issue" with PC4..7 on a JTAG chip like mega16 isn't it always the JTAGEN ??

 

Assuming the change of fuse has failed simply try:

void main(void)
{
    MCUCR = (1 << JTD);
    MCUCR = (1 << JTD);
// Declare your local variables here

I'd be astonished if that didn't fix it.

Many thanks to you for checking and answering my post.

You are not going to believe this. I swear the Satan himself. I added this to disable the JTAGEN and it didn't work. 

this problem is getting frustrating.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have likely blown the chip! Look at the VCC being read by the programmer.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kooroshi60 wrote:
I added this to disable the JTAGEN and it didn't work.
theusch wrote:
Tell toolchain, version, and optimization settings. Tell AVR clock speed, and supply voltage level. If still confusing after you work through that, post the generated code from the compiler.

I've lost track a bit.  What do we know so far about my questions?

 

-- depending on the toolchain and optimization settings and the phase of the moon, the simple sequence may not follow the 4-cycle limitation.  Thus, the request for the generated code.  Too big?  Then at least post that piece.

 

-- too big?!?  Then CREATE a sanity-check simple program.  Does that work?  Then obviously some other part of the "big" code is messing it up.  Heck, it could even be a rogue pointer to I/O space.  Doesn't work?  Then when you post the test program and tell toolchain and settings and such, and/or post generated code, and show schematic, and tell us what "doesn't work" means and how you are testing -- things will probably become apparent.

 

[side note from experience, with puzzling results such as yours:  After creating the sanity-check program from scratch and that "works", take the big program, leave essentially intact, and "short circuit" by placing the sanity check code right after all the init stuff.  Does it work?  If so, then move it further down and repeat.  The catch is something like an infinite loop with

 wdr;
 set suspect pin(s) high
 delay a good part of a second;
 set suspect pins low
 delay a good part of a second;

If only a voltmeter and not LED, then make the delay a few seconds to get the reading to register.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
You have likely blown the chip! Look at the VCC being read by the programmer.

That's what I thought too.So I bought another 2 chips but they are all the same. The programming voltage is 5.5 volts (shown in Atmel studio).

I actually use my universal programmer which is quicker and has more user friendly GUI.

At this point I'm thinking maybe I have bought fake Chinese chips.

I have located the original ATMEGA16 chips in my city and will give it a try a couple of days later.

Thank you so much

Ciao!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why is VCC so high? It usually is 5V, if it reads 5.7V at this point is it likely to higher or even lower ? How are you powering this board?

 

With both AVCC and pin 31 originally unconnected you were likely damaging any new chip plugged in.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well the code on dropbox was almost identical to that posted in #1. However I can now see you ARE writing to PORTC.4 & PORTC.5.

 

I also see:

void main(void)

{

MCUCR = (1 << JTD);

MCUCR = (1 << JTD);

{ Ooh now that is interesting - copy & pasting stuff from Visual Studio Code into Firefox on Ubuntu preserves the colouring }

 

Should that be MCUCSR instead ?

It's irrelevant really because it'll make no difference - I think your JTAG is disabled. If JTAG were enabled TDO would be an I/P; and on these older designs of megaAVR it would be a floating I/P. Not an O/P low.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Following your suggestions I checked my chips with the following code and they were all OK.

LEDs started blinking properly.

Now I'm sure my Chips and Fuse Bits setting are OK and there must be something wrong in the project code

Unfortunately I am not enough skilled to analyze the code and track the problem.

Thank you so much for your patience and help.

#include<avr/io.h>
#include<util/delay.h>

int main (void)
{
	  DDRC=0xFF;
	  while(1)
	  {
		  PORTC=~PORTC;
		  _delay_ms(1000);
	  }
}

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
I've lost track a bit. 
Me too. At one stage we have:

#define output1     PORTC.2
#define output2     PORTC.3
#define lcd_light   PORTA.3

So that is clearly Codevision code. But then at another stage we have:

#include<avr/io.h>
#include<util/delay.h>

int main (void)
{

and that's clearly avr-gcc. So I don't know which C compiler it is that he's using.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

theusch wrote:
I've lost track a bit. 
Me too. At one stage we have:

#define output1     PORTC.2
#define output2     PORTC.3
#define lcd_light   PORTA.3

So that is clearly Codevision code. But then at another stage we have:

#include<avr/io.h>
#include<util/delay.h>

int main (void)
{

and that's clearly avr-gcc. So I don't know which C compiler it is that he's using.

It is originally like below in Codevision AVR. so it is not an issue. I was just trying to use other pins.

#define output1     PORTC.4
#define output2     PORTC.5
#define lcd_light   PORTA.3

My test code is written in Atmel studio of course. it is easier for me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
and that's clearly avr-gcc. So I don't know which C compiler it is that he's using.

So then we don't know optimization level, so the JTAG sequence might not work.  Which is >>why<< I asked a number of related questions, but only a few are answered/addressed.  This is like pulling teeth.

 

We have now heard that the "sanity check" program works.  What did I say about that?

theusch wrote:
After creating the sanity-check program from scratch and that "works", take the big program, leave essentially intact, and "short circuit" by placing the sanity check code right after all the init stuff. Does it work? If so, then move it further down and repeat. The catch is something like an infinite loop with...

 

It is very frustrating to try to help an OP that has a puzzling situation which is continued to be worked on, but suggestions are not taken.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Trovato!

Finally the problem is solved! I simply used PORTB pins and now my timer works perfectly.

But the mystery of PORTC remains unsolved. I blame the fake, low quality Chinese components (AVR chips in my case).

China is trashing the world with it's "Communist grade" products. We know it but it is almost impossible to recognize the authentic electronic components.

Anyway, thank you guys very much for your suggestions. I learned a lot on this issue. 

Ciao!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anyway, thank you guys very much for your suggestions. I learned a lot on this issue. 

But apparently not how to solve the actual problem.

 

Instead, you lay blame at the feet of an entire nation:

China is trashing the world with it's "Communist grade" products. We know it but it is almost impossible to recognize the authentic electronic components.

... and without any proof.  What's more, you've made it political, which is verboten here.

 

In fact, you yourself have proven that it is not the chip:

Following your suggestions I checked my chips with the following code and they were all OK.

LEDs started blinking properly.

If only you would avail yourself of the advice given in this thread.  Hint:  #37.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kooroshi60 how come you are throwing in Italian words? smiley

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly