# [SOLVED]Problem with atmega16

Status
Not open for further replies.

#### sriblue7

##### Member level 1
Hi! i am using an atmega16L microcontroller for processing the input from ht-12D and based on this input appropriate pins of microcontroller are made high.I have used port B as input and ports A and C for output.I have set the fuse bits as lfuse=0xFF and hfuse=0xC9 for using an external 8Mhz crystal and to use port C as i/o pins.I use parallel port programmer(dapa).I use this setup for making the receiver part of my robot.
The problem is i am getting the desired output only if i switch off and switch on my power supply(i am not getting my output immediately).What could be the problem?

Last edited:

#### bigdogguru

Could you post or upload your code and a schematic of you interface between the ATMEGA16L and the HT-12D, so that one of us could review it?

#### sriblue7

##### Member level 1
I have attached the schematic with code.

#### Attachments

• 27.8 KB Views: 11

#### pranam77

The circuit looks ok..but the oscillator resistor for the HT12D should be 47K and not more than that. Just use a fixed 0.25 watt in place. Too note that the HT12E must use a 1M resistor. Cheers

sriblue7

### sriblue7

points: 2

#### bigdogguru

Code:
#include<avr/io.h>

int main()
{
unsigned char y;
DDRB=0b00000000;
PORTB=0b11110000;//enabling pull ups for PB7-PB3
y=PINB;
DDRA=0b11111111;//Port A o/p
DDRC=0b11111111;//Port C o/p

if(y==0b00010000)//Forward
{
PORTA=0b10000000;
PORTC=0b00000000;
}
else if(y==0b00100000)//Backward
{
PORTA=0b01000000;
PORTC=0b00000000;
}
else if(y==0b00110000)//Left
.....
.....
.....
else
{
PORTA=0b00000000;
PORTC=0b00000000;
}

return 0;
}

It's a straight one shot, no loop, so if you're lucky it catches the first transmitted command and then ends. Try encapsulating the " if, else" statements in a:

Code:
while(1)
{

}

And change the resistor values as Pranam77 suggested and you should be good to go.

Ciao

sriblue7

### sriblue7

points: 2

#### Hi-Tone

##### Member level 1
Like above said. You do all the setup inside the main loop too. You can put that outside the main loop, so you sort of setup your system first - and only once. This should sort the problem out or get you a lot further.

sriblue7

### sriblue7

points: 2

#### sriblue7

##### Member level 1
Thank u.I got the expected output after including the while loop.However i am getting only 1.5V(instead of 5V as expected) as HIGH at the output pins.What could be the problem?

#### bigdogguru

However i am getting only 1.5V(instead of 5V as expected) as HIGH at the output pins.What could be the problem?
Which output pins? All of PORTA and PORTC?

How are you measuring the output voltage?

I'll take another look at the schematic.

Ciao

#### sriblue7

##### Member level 1
The pins from which i need HIGH voltage i am getting as 1.5V instead of 5V.I measured with respect to ground(common for both ht 12 D and microcontroller).

---------- Post added at 14:45 ---------- Previous post was at 14:00 ----------

I am getting 5V at the output for other programs like glowing or blinking LED.

#### bigdogguru

Do you have pull-up resistors installed? If not I would suggest adding them.

#### nandhu015

Is the Jtag disabled ?

#### sriblue7

##### Member level 1
Thank you! I found out the mistake it was with my program.Now I am getting 5V at the outputs as expected.

Status
Not open for further replies.