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.

send data to the serial port using proteus based ATmega16

Status
Not open for further replies.

aminanto

Newbie level 6
Joined
Nov 10, 2012
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,385
I recently made ​​a small project for my final project,
This project involves the transmission of data via the serial port.
I am using proteus to simulate the system as a whole and based on ATmega16.
since my laptop does not have a serial port so I
using Virtual Serial Port Emulator. While I use huperterminal to receive data transmitted by the microcontroller. I just do not have the data sent by the microcontroller.
Someone please help me, I've thought about it for hours and did not manage to make the data sent ..

This is a screenshot of proteus and code. ..
Simulation.png

Code:
//Program for ADC to read from channel 0 and show the 8 bit o/p on PORTB
// send the reading from ADC to Serial Port

#include <mega16.h>
#include <stdlib.h>
#include <delay.h>
#include <io.h>


#define ADC_VREF_TYPE 0x40
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((12000000/ (USART_BAUDRATE*16))) - 1)
//------------------------------------------------

void ADC_init(void) // Initialization of ADC
{
ADMUX=(1<<REFS0);
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);    // faktor pembagi 128
}

void usart_init()
{
UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception 

circuitry
UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1); 
// Use 8-bit character sizes
 
UBRRL = BAUD_PRESCALE; 
// Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
// into the high byte of the UBRR register
}

void usart_putch(unsigned char send)
{
while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
// for more data to be written to it
UDR = send; // Send the byte 
}

/*void USART_transmit(unsigned char data)
{
  while((UCSRA & 0x20)==1)
  { 
  UDR=data; }
    }*/
/*void SEND_reading(unsigned char abc)
{
    unsigned char k,l,m;
    k=abc/100;
    l=(abc/10)%10;  
    m=abc%10;
    USART_transmit(k);
    USART_transmit(l);
    USART_transmit(m);
    USART_transmit(',');
    }  */
/*unsigned int ADC_read(unsigned char ch)
{
ch= ch & 0b00000111; // channel must be b/w 0 to 7
ADMUX |= ch; // selecting channel
 
ADCSRA|=(1<<ADSC); // start conversion
while(!(ADCSRA & (1<<ADIF))); // waiting for ADIF, conversion complete
ADCSRA|=(1<<ADIF); // clearing of ADIF, it is done by writing 1 to it
 
return ADCW;
}   */


// Read the AD conversion result
unsigned int ADC_read(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|=0b01000000;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==1);
ADCSRA|=0b00000;
return ADCW;
}


void main(void)
{
unsigned int value;
DDRB=0xFF;
DDRD=0x03;
ADC_init(); // Initialization of ADC
usart_init();
// ch=0;
while(1)
{
value=ADC_read(0);
value=value*500/1024;
PORTB=value;
//SEND_reading(value);
usart_putch(value);
delay_ms(10);
  } 
}

one more, I'm using code vision

I would greatly appreciate any help you guys ..
 

Connect the RxD of Virtual Terminal (VT) to TxD of mcu and connect TxD of VT to RxD of mcu in Proteus and simulate.
 

Connect the RxD of Virtual Terminal (VT) to TxD of mcu and connect TxD of VT to RxD of mcu in Proteus and simulate.

what do you mean I have to eliminate the max232 and directly connect to the DB9?
 

not in the real hardware but in the Proteus simulation.
 

I still do not get it ..
I have tried as you suggested, it might be more obvious with the image:

what is wrong about it ..:cry:

simulasi 2.png
 

zip an post the proteus file and the project files.

Is this
Code:
 k=abc/100;
    l=(abc/10)%10;  
    m=abc%10;
or
Code:
 k=abc/100 + 48;
    l=(abc/10)%10 + 48;  
    m=abc%10 + 48;

Right click VT in proteus and choose Edit Properties and see if the baud rate is set to 9600.
 
Last edited:

thank you for replying to this,

Ok, here is the files ..
**broken link removed**

contains proteus file and the code themselves ..
 

Can you post the hex file you have compiled. I don't have CodeVisionAVR. You have commented out the adc_read() function definition. remove the commenting. compile the code and zip and post the hex file.

You have commented out the adc_read() function. so the value of variable value will be 0.

If possible post the complete CodeVisionAVR project files. I have downloaded and installed CodeVisionAVR Evaluation Copy. I will try to compile and check the simulation.

In the code you have used PA0/ADC0 for adc input, but you have not configured DDRA=0xFE; Have you set PA0 as analog port in the code?
 
Last edited:

There are two adc_read function,
output of adc is correct if you try in proteus. follow changes lm35..

let me clean up the code, a bit:
Code:
//Program for ADC to read from channel 0 and show the 8 bit o/p on PORTB
// send the reading from ADC to Serial Port

#include <mega16.h>
#include <stdlib.h>
#include <delay.h>
#include <io.h>


#define ADC_VREF_TYPE 0x40
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((12000000/ (USART_BAUDRATE*16))) - 1)
//------------------------------------------------

void ADC_init(void) // Initialization of ADC
{
ADMUX=(1<<REFS0);
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);    // faktor pembagi 128
}

void usart_init()
{
UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1); 
// Use 8-bit character sizes
 
UBRRL = BAUD_PRESCALE; 
// Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
// into the high byte of the UBRR register
}

void usart_putch(unsigned char send)
{
while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
// for more data to be written to it
UDR = send; // Send the byte 
}

// Read the AD conversion result
unsigned int ADC_read(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|=0b01000000;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==1);
ADCSRA|=0b00000;
return ADCW;
}


void main(void)
{
unsigned int value;
DDRB=0xFF;
DDRD=0x03;
ADC_init(); // Initialization of ADC
usart_init();
// ch=0;
while(1)
{
value=ADC_read(0);
value=value*500/1024;
PORTB=value;
//SEND_reading(value);
usart_putch(value);
delay_ms(10);
  } 
}

the HEX file:
**broken link removed**

I hope I'm lucky today, through you
 

I am getting something on VT. See the image. Add DDRA = 0xFE; and compile and send the hex file to me @ internetuser2k11@gmail.com

Yes. you have used this
Code:
 usart_putch('C');
and I am getting that on the VT. It is working. you have to convert the contents of the variable value to char.
and transmit it to VT.

Please compile codes in code1.txt and code2.txt seperately and send me the two hex files. compile for 12 MHz.
 

Attachments

  • rs232.jpg
    rs232.jpg
    155.1 KB · Views: 124
  • code 1.txt
    2.4 KB · Views: 88
  • code 2.txt
    2.6 KB · Views: 45
Last edited:

I have modified the code, and convert the ADC output value ..

Code:
void main(void)
{
unsigned int value;
DDRB=0xFF;
DDRA=0xFE;
ADC_init(); // Initialization of ADC
usart_init();
// ch=0;
while(1)
{
value=ADC_read(0);
value=value*500/1024;
PORTB=value;
value=(char)value;
//SEND_reading(value);
usart_putch(value);
delay_ms(10);
  } 
}

the HEX file, I have been sent to your email ..
 

Code:
 value=(char)value;
will not work because value is an int type variable and you cannot store char(value) to int type variable. when char(value) is done it has to be stored in a char or string variable. Please compile the code1.txt and code2.txt codes and send me the 2 hex files.

The adc is working and also the usart putchar(). please send the 2 hex files
 

I have sent it,
But up until now, I did not get any in VT,.:-(
 

I got CCCC in VT because of putch('C') in :serial test 3.hex". Send the code used to create "Serial test 3.hex"

How to generate .cof or .coff files in CodeVisionAVR?
 
Last edited:

**broken link removed**

- - - Updated - - -

I'm also working on the code, trying to figure out what exactly the problem is ...
 

Can I generate .cof or .coff files in evaluation version of CodeVisionAVR. If no. send me the .coff file for the code in code2.txt
 

You should compile and built you project ..

- - - Updated - - -

in order to compile the c code, you should create a project first ..
Just create a new project file, bases on ATmega family,
there will be a new window, click "Generate PrograSave Exit"

- - - Updated - - -

I do not know what to say, man
but I really appreciate your help ..
hopefully this will end quickly ..
and have a cup of coffee
 
Last edited:

Send me the coff files and I will debug in proteus and see what is wrong. edit your last past and remove the link you posted for codevisionavr otherwise you will get banned from the forum for posting software links. be quick.

I am attaching code3.txt. Compile it for 8 MHz and send me the .coff file of it.

OK. got the adc working and also got CCCCCC on VT. Just have to display value.
 

Attachments

  • code 3.txt
    2.7 KB · Views: 58
  • adc n rs232.jpg
    adc n rs232.jpg
    238.4 KB · Views: 124
Last edited:

**broken link removed**

- - - Updated - - -

I found that the CCCC output is not depend on character that sent by micro ..

here is the COF file, of code you just sen:
**broken link removed**
 
Last edited:

Yes, It is a different Character. If I compile the code for 8 MHz adc and usart is working, but VT shows some C typr character and not the char value of value or 'C'.

You did not send the .cof file for code3.txt
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top