Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ATMEGA162 using AVR studio with WIN AVR PortC as output problem..

Status
Not open for further replies.

drbizzarow

Advanced Member level 1
Joined
May 24, 2006
Messages
414
Helped
25
Reputation
50
Reaction score
15
Trophy points
1,298
Activity points
3,662
Dear All,

I am using AVR studio and programming in C........i am facing following problem:

When i send any byte to PortC .....PINC.0 to PINC.3 work ok and show the byte lower nibble but PINC.4 to PIN.7 remain unchanged and always shows HIGH on their pins.

Please see my code............

#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>

/* CPU frequency */
#define F_CPU 16000000UL
#define USART_BAUDRATE 9600

#define BAUD_PRESCALE (((F_CPU) / (USART_BAUDRATE * 16UL)) - 1)

#define LEFT 'L'
#define RIGHT 'R'
#define FRONT 'F'
#define BACK 'B'
#define KNEE 'K'
#define STOP 'S'
#define All 'A'

#define SERIAL_PACKET_SIZE 10

#define BUZZER_ON PORTB |= 0x01; //Buzzer 0N
#define BUZZER_OFF PORTB &= 0xFE; //Buzzer OFF

#define SCAN_MTR_LEFT PORTC = PORTC |= 0x03; PORTC &= 0xFD;
#define SCAN_MTR_RIGHT PORTC = PORTC |= 0x03; PORTC &= 0xFE;
#define SCAN_MTR_STOP PORTC = PORTC |= 0x03;

#define LEFT_MOTOR_OFF PORTC |= 0x08;
#define LEFT_MOTOR_ON PORTC &= 0xF7;

#define FRONT_MOTOR_OFF PORTC |= 0x04;
#define FRONT_MOTOR_ON PORTC &= 0xFB;

#define RIGHT_MOTOR_OFF PORTC |= 0x20;
#define RIGHT_MOTOR_ON PORTC &= 0xDF;

#define BACK_MOTOR_OFF PORTC |= 0x10;
#define BACK_MOTOR_ON PORTC &= 0xEF;

unsigned char SerialBuffIndex = 0;
unsigned char SerialBuff[SERIAL_PACKET_SIZE];
unsigned char CurDistance;
unsigned char CurDirection;
unsigned char SmtrDir;
unsigned char Tbyte;


ISR(USART0_RXC_vect)
{
//ReceivedByte = UDR0; // Fetch the recieved byte value into the variable "ByteReceived"
//while ((UCSR0A & (1 << UDRE0)) == 0) {};
//UDR0 = ReceivedByte; // Echo back the received byte back to the computer

SerialBuff[SerialBuffIndex] = UDR0;

if(SerialBuff[SerialBuffIndex] == 'R')
{
SerialBuff[0] = 'R';
SerialBuffIndex = 0;
}

SerialBuff[SerialBuffIndex] = SerialBuff[SerialBuffIndex] - 0x30;

if(SerialBuff[SerialBuffIndex] == 0x0D)
{
CurDistance = ((SerialBuff[1]*100)+(SerialBuff[2]*10)+SerialBuff[3]);
SerialBuffIndex = 0;
}

SerialBuffIndex++;
if(SerialBuffIndex >= SERIAL_PACKET_SIZE)
{
SerialBuffIndex = 0; // incase of serial buffer overflow
}
}

int main(void)
{
char x, y;

DDRA = 0xFF;
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0xFE;
DDRE = 0x00;

PORTA = 0xFF;
PORTB = 0xFE;
PORTC = 0xFF;
PORTD = 0xFF;
PORTE = 0xFF;

//DDRA = 0x00;
//DDRE = 0x00;

UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Turn on the transmission and reception circuitry
UCSR0C |= (1 << UCSZ00)| (1 << UCSZ01); // Use 8-bit character sizes
UBRR0L = 50;//BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRR0H = 0; //(BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
UCSR0B |= (1 << RXCIE0); // Enable the USART Recieve Complete interrupt (USART_RXC)
sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processed

_delay_ms(1000);

while(1)
{
UDR0 = 'c';
PORTC = 0xFF;
//RIGHT_MOTOR_OFF // this line is also not works
_delay_ms(1000);

UDR0 = 'v';
PORTC = 0x00; //does not make effect on upper nibble PORTC pins (ie: PortC.5 to PortC.7) these pin remains high
///RIGHT_MOTOR_ON // this line is also not works
_delay_ms(1000);
}
return 0;
}
 

PC4 to PC7 are JTAG pins by default, have you disabled the JTAG fuse (JTAGEN)?

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top