Code changes - (AT90S2313 ==> AT TINY2313)

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

Hi,

Could you please help me to make the required changes in order to use the C code intended to be used to AT90S2313, to TINY2313(A)?
I asked help with a previous post in the past. "Clawson" help me very much to do that, but something need changes and this is serial routine because registers have some changes.I tried some changes without success.
My old post has the following subject: "GCC Library replacements". In fact the only problem is that when a key is pressed, the micro-controller does not send it to PC using serial port...

Thanks,

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

I suggest you post the code you currently have problems with. As with all these things it's a case of opening the 90S2313 and tiny2313 datasheets side by side and see exactly what was changed in the peripheral(s) you are trying to use.

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

Let's try a Google search ...
http://www.lmgtfy.com/?q=migrati...

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

The old (initial code by the Author and also the other one which is modified by Clawson are in the following link:

https://www.avrfreaks.net/index.p...

The second (modified by Clawson) works almost fine. The only issue is that does not send the characters of keypad to PC.

I tried to use that, but for the time being with no success...

"AVR091: Replacing AT90S2313 by ATtiny2313"

Thank You !

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

Quote:

I suggest you post the code you currently have problems with.

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

Quote:

The only issue is that does not send the characters of keypad to PC.


Is your AVR really running at the speed you think it is? What is the clock source? Have you configured the USART to use the bit rate that the AVR is actually sending?

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

Of curse !

 

This is for sure ...

 

 

 

 

 

Thank You !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
// rf pad by Alberto Ricci Bitti - a.riccibitti@iname.com
// version 2 - 1 may 2000
// designed for AT90S2313 and GNU C compiler (-Os option used)
// this sofwtware is distributed under the GNU public license (www.gnu.org) 

 
#include <io.h>
#include <inttypes.h>
#include <interrupt.h>
#include <signal.h>


//replace here your own ASCII key combination / 12 bit rf codes pairs
//very important: the combination must be the same length as the key_combination[] (see below)
#define COMBINATION_1 	"111111"
#define RF_CODE_1		0xAAA		//will be AA 0A in code dump

#define COMBINATION_2	"222222"
#define RF_CODE_2		0xBBB		//will be BB 0B in code dump

#define COMBINATION_3	"333333"
#define RF_CODE_3		0xCCC		//will be CC 0C in code dump

//dirty trick: making it a volatile array, we force compiler to take codes from RAM
//instead of using optimized direct instructions as ldi.
//this allows modifying the codes directly on the hex code for those without a compiler
volatile unsigned int codes[3] = { RF_CODE_1, RF_CODE_2, RF_CODE_3 };

//handy bit masking macro
#define byte( b7,b6,b5,b4,b3,b2,b1,b0) (b7*128+b6*64+b5*32+b4*16+b3*8+b2*4+b1*2+b0)

#define F_CPU            4000000      /* 4Mhz */
#define UART_BAUD_RATE      9600      /* 9600 baud */
#define UART_BAUD_SELECT (F_CPU/(UART_BAUD_RATE*16l)-1)

// lo level hardware drive macros
#define BEEPER_ON	sbi(PORTB, 1)
#define BEEPER_OFF  cbi(PORTB, 1)
#define RF_ON       sbi(PORTB, 0)
#define RF_OFF      cbi(PORTB, 0)
#define SEL_COL_0   { sbi(PORTB, 4); sbi(PORTB, 5); sbi(PORTB, 6); cbi(PORTB, 7); }
#define SEL_COL_1   { sbi(PORTB, 4); cbi(PORTB, 5); sbi(PORTB, 6); sbi(PORTB, 7); }
#define SEL_COL_2   { sbi(PORTB, 4); sbi(PORTB, 5); cbi(PORTB, 6); sbi(PORTB, 7); }
#define SEL_COL_3   { cbi(PORTB, 4); sbi(PORTB, 5); sbi(PORTB, 6); sbi(PORTB, 7); }

#define SEL_COL_ALL { cbi(PORTB, 4); cbi(PORTB, 5); cbi(PORTB, 6); cbi(PORTB, 7); }

// important constants 
#define MAX_ROWS 4
#define MAX_COLUMNS 4
#define MAX_KEYS (MAX_ROWS * MAX_COLUMNS)

#define NO_COLUMN MAX_COLUMNS
#define NO_ROW MAX_ROWS
#define NO_KEY '?'

//keyboard ASCII matrix, replace your own characters here
//DON'T USE 0x00 as it breaks string compare
const unsigned char keys[MAX_ROWS][MAX_COLUMNS] = {
	{'1', '2', '3', 'A' },	
	{'4', '5', '6', 'B' },	
	{'7', '8', '9', 'C' },	
	{'*', '0', '#', 'D' }
};

//function prototypes
void wait(unsigned long delay);
unsigned char find_column(void);
unsigned char decode_row( unsigned char col);
unsigned char key_detected(void);



//returns 1 if key pressed, 0 otherwise
unsigned char key_detected(void)
{	register unsigned char tmp;
	tmp = inp(PIND);
	tmp &= byte(0,0,1,1, 1,1,0,0);
	if ( tmp == byte(0,0,1,1, 1,1,0,0) )
		return 0;
	return 1;
}

// returns the column of the key being pressed
// NO_COLUMN if no keys pressed
unsigned char find_column(void)
{
	unsigned char c;
	
	for (c=0; c<MAX_COLUMNS; c++)
	{	switch(c)
		{
		case 0: SEL_COL_0; break;
		case 1: SEL_COL_1; break;
		case 2: SEL_COL_2; break;
		case 3: SEL_COL_3; break;
		};
		wait(100);
		if ( key_detected() )
			break;
	}
	return c;
};

// returns the ASCII code of key being pressed, NO_KEY if no keys pressed
// requires key's column 
unsigned char decode_row( unsigned char col)
{
	unsigned char mask, row;

	if (col == NO_COLUMN)
		return NO_KEY;  
			
	mask = inp(PIND) & byte(0,0,1,1, 1,1,0,0);
	switch(mask)
	{
	case byte(0,0,1,1, 1,0,0,0):
		row = 2;
		break;
	case byte(0,0,1,1, 0,1,0,0):
		row = 1;
		break;
	case byte(0,0,1,0, 1,0,0,0): //diode effect: two bits low at once
		row = 0;
		break;
	case byte(0,0,0,1, 0,1,0,0): //diode effect: two bits low at once
		row = 3;
		break;
	default: 
		return NO_KEY;
	};
	return keys[row][col];
};

// simple wait loop, compiler and optimization dependant (-Os option used)
void wait(unsigned long delay)
{
	while (delay--)
	{
		asm("nop");
	};
};
	
// calibration macro for the above wait loop
#define uS(x)  ( ( (x) * 550L)/1000)

// define sleep macro
#define sleep()  asm volatile ("sleep" ::)

// define handlers, just to be safe
SIGNAL(SIG_INT0)
{
};

SIGNAL(SIG_INT1)
{
};


// generate the RF code in the 11 LSB of the parameter
// the code is repeated 15 times
// 270 uS and 550 uS are the times measured on my commercial remote
// control with a fresh battery
void rf_code(unsigned int code)
{
	unsigned int mask;
	unsigned char times;
	
	for (times=0; times < 15; times++)
	{	
		
		// start bit
		RF_ON;
		wait(uS( 270 ));
		
		for (mask = 1 << 11; mask != 0; mask >>= 1)
		{
			RF_OFF;
			if (code & mask)
			{
				//tx 0
				wait( uS(550) );
				RF_ON;
				wait (uS(270) );
			}
			else			
			{	//tx 1
				wait( uS(270) );
				RF_ON;
				wait( uS(550) );
			};
		};
		RF_OFF;	
		wait( uS( 10000));
	};
}
		

int main( void )
{
   	unsigned char key_sequence[ sizeof(COMBINATION_1) ] = "??????";  //be sure this is as long as your combination!
   	unsigned char i;					//used to shift incoming combination string
   	
	outp(0xff,PORTB);           			// all pins pulled up on inputs 
	outp(0xff,DDRB);           				// use all pins on PortB for output 

	outp(0xff,PORTD);           			// all pins pulled up on inputs 
	outp(0x00,DDRD);           				// use all pins on PortD for input 
	
	//uart init: enable RxD/TxD and ints, then set baud rate
    outp(( 1<<RXEN)|(1<<TXEN), UCR );       
    outp( (unsigned char) UART_BAUD_SELECT, UBRR );          
    
	//enable sleep, power-down mode, interrupt on low level of either INT0 or INT1
	outp( (1<<SE)|(1<<SM), MCUCR);

    //enable external interrupts
    outp( (1<<INT1)|(1<<INT0), GIMSK);
	
	// tell the world we're alive with a long beep
   	wait(400000);
   	BEEPER_OFF;
   	RF_OFF;
   	
   	for ( ; ; )
   	{	
	   	
	   	
		// all keys active
		SEL_COL_ALL;
		wait(10000);

   		//wait for the key being released
		while ( key_detected() )
		{
			wait(50000);
		};
		
		//time to go bed! re-enable interrupts and shut off
		sei();
		sleep();
			
	   	// ...ZZZ...  ...the AVR stays asleep until next keypress...
	   	
	   	//key pressed: dummy instruction just to be safe 
	   	//(some micros skip the instruction next to sleep)
	   	asm("nop");
	   	
	   	// avoid annoying interrupts until key released
		cli(); 

		//shift combination left, decode key and add it to current combination
		i = 0;
		while( ( key_sequence[i] = key_sequence[i+1]) != 0)
			i++;
		// i points to last character in string
		key_sequence[ i ] = decode_row( find_column() );

		// send key ASCII code to serial port
		outp(key_sequence[ i ], UDR);
	
		// compare combination to valid codes
		// (add here other combinations if needed)
		if ( ! strcmp(key_sequence, COMBINATION_1)	)	
		{
				BEEPER_ON;
				rf_code( codes[1] );	//indirect addressing: see codes[] declaration
				BEEPER_OFF;
   		}
   		else if ( ! strcmp(key_sequence, COMBINATION_2)	)	
		{
				BEEPER_ON;
				rf_code( codes[2] );
				BEEPER_OFF;
   		} 
   		else if ( ! strcmp(key_sequence, COMBINATION_3)	)	
		{
				BEEPER_ON;
				rf_code( codes[3] );
				BEEPER_OFF;
   		};
   		// key beep
   		BEEPER_ON;
   		wait(15000);
   		BEEPER_OFF;
	};
};

 

 

 

 

Thank You !

 

 

Last Edited: Fri. Oct 10, 2014 - 08:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The forum appears to have eaten the #include <something>'s in that!

 

Perhaps all is not lost as the project is here:

 

http://www.riccibitti.com/rf_pad...

 

with the code in this zip file:

 

http://www.riccibitti.com/rf_pad...

 

so the includes are:

#include <io.h>
#include <inttypes.h>
#include <interrupt.h>
#include <signal.h>

In "modern" GCC that would translate to:

#include <avr/io.h>
#include <avr/interrupt.h>

(though curiously it doesn't actually contain interrupts??)

 

Also, because of the very old macros used in that code you would need to add:

#include <compat/deprecated.h>

It might compile after that though it appears to be calling a function called wait() but I don't see the implementation in that code?

 

EDIT: actually the code in the file in the .zip I linked to is quite different to the code you posted. It has wait():

// simple wait loop, compiler and optimization dependant (-Os option used)
void wait(unsigned long delay)
{
	while (delay--)
	{
		asm("nop");
	};
};

but it's also different in many other ways too. As it's what he has linked from the web page where the project s documented I can't help thinking it's the "better" version?

Last Edited: Fri. Oct 10, 2014 - 01:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Clawson !

 

Could you please, inform me:

 

  1. If  that code can be compiled with Codevision , instead of GNU ?
  2. There are some differences regarding UART registers between 90S2313 and tiny2313 or tiny2313A. Is that correct ?
  3. "Also, because of the very old macros used in that code you would need to add: #include <compat/deprecated.h>" Because I have never used macros, is it possible please to let me know what are those, in a brief ? I have an idea but I would like to be sure...

 

    As far as interrupt is concerned, code uses interrupts library and if you see the schematic there are two diodes, in order to wake-up the μC.

 

 

P.S In my previous post, I replaced the code with the original one.I am not sure was exactly happened with the previous.Probably it was an attempt to solve the problem...

 

 

Thank You,

 

bnsavr

 

 

 

 

   

 

Last Edited: Fri. Oct 10, 2014 - 08:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was bored.    So I downloaded the ZIP file pointed from clawson.    And compiled with CV.

 

// rf pad by Alberto Ricci Bitti - a.riccibitti@iname.com
// version 2 - 1 may 2000
// designed for AT90S2313 and GNU C compiler (-Os option used)
// this sofwtware is distributed under the GNU public license (www.gnu.org) 

 
#include <io.h>
//#include <inttypes.h>
//#include <interrupt.h>
//#include <signal.h>
//.kbv several macros for CV. 
//.kbv Actual Code edits are marked with .kbv
//.kbv note that there is a #warning about codes[3] out of range
#include <string.h>
#define inp(p)    p
#define outp(val, p) p = val
#define sbi(p, b) p |= (1<<(b))
#define cbi(p, b) p &= ~(1<<(b))
#define cli()     #asm("cli")
#define sei()     #asm("sei")
#define SIGNAL(x) interrupt [x] void isr##x(void)
#define SIG_INT0  EXT_INT0
#define SIG_INT1  EXT_INT1

//replace here your own ASCII key combination / 12 bit rf codes pairs
//very important: the combination must be the same length as the key_combination[] (see below)
#define COMBINATION_1     "111111"
#define RF_CODE_1        0xAAA        //will be AA 0A in code dump

#define COMBINATION_2    "222222"
#define RF_CODE_2        0xBBB        //will be BB 0B in code dump

#define COMBINATION_3    "333333"
#define RF_CODE_3        0xCCC        //will be CC 0C in code dump

//dirty trick: making it a volatile array, we force compiler to take codes from RAM
//instead of using optimized direct instructions as ldi.
//this allows modifying the codes directly on the hex code for those without a compiler
volatile unsigned int codes[3] = { RF_CODE_1, RF_CODE_2, RF_CODE_3 };

//handy bit masking macro
#define byte( b7,b6,b5,b4,b3,b2,b1,b0) (b7*128+b6*64+b5*32+b4*16+b3*8+b2*4+b1*2+b0)

#define F_CPU            4000000      /* 4Mhz */
#define UART_BAUD_RATE      9600      /* 9600 baud */
#define UART_BAUD_SELECT (F_CPU/(UART_BAUD_RATE*16l)-1)

// lo level hardware drive macros
#define BEEPER_ON    sbi(PORTB, 1)
#define BEEPER_OFF  cbi(PORTB, 1)
#define RF_ON       sbi(PORTB, 0)
#define RF_OFF      cbi(PORTB, 0)
#define SEL_COL_0   { sbi(PORTB, 4); sbi(PORTB, 5); sbi(PORTB, 6); cbi(PORTB, 7); }
#define SEL_COL_1   { sbi(PORTB, 4); cbi(PORTB, 5); sbi(PORTB, 6); sbi(PORTB, 7); }
#define SEL_COL_2   { sbi(PORTB, 4); sbi(PORTB, 5); cbi(PORTB, 6); sbi(PORTB, 7); }
#define SEL_COL_3   { cbi(PORTB, 4); sbi(PORTB, 5); sbi(PORTB, 6); sbi(PORTB, 7); }

#define SEL_COL_ALL { cbi(PORTB, 4); cbi(PORTB, 5); cbi(PORTB, 6); cbi(PORTB, 7); }

// important constants 
#define MAX_ROWS 4
#define MAX_COLUMNS 4
#define MAX_KEYS (MAX_ROWS * MAX_COLUMNS)

#define NO_COLUMN MAX_COLUMNS
#define NO_ROW MAX_ROWS
#define NO_KEY '?'

//keyboard ASCII matrix, replace your own characters here
//DON'T USE 0x00 as it breaks string compare
const unsigned char keys[MAX_ROWS][MAX_COLUMNS] = {
    {'1', '2', '3', 'A' },    
    {'4', '5', '6', 'B' },    
    {'7', '8', '9', 'C' },    
    {'*', '0', '#', 'D' }
};

//function prototypes
void wait(unsigned long delay);
unsigned char find_column(void);
unsigned char decode_row( unsigned char col);
unsigned char key_detected(void);



//returns 1 if key pressed, 0 otherwise
unsigned char key_detected(void)
{    register unsigned char tmp;
    tmp = inp(PIND);
    tmp &= byte(0,0,1,1, 1,1,0,0);
    if ( tmp == byte(0,0,1,1, 1,1,0,0) )
        return 0;
    return 1;
}

// returns the column of the key being pressed
// NO_COLUMN if no keys pressed
unsigned char find_column(void)
{
    unsigned char c;
    
    for (c=0; c<MAX_COLUMNS; c++)
    {    switch(c)
        {
        case 0: SEL_COL_0; break;
        case 1: SEL_COL_1; break;
        case 2: SEL_COL_2; break;
        case 3: SEL_COL_3; break;
        };
        wait(100);
        if ( key_detected() )
            break;
    }
    return c;
};

// returns the ASCII code of key being pressed, NO_KEY if no keys pressed
// requires key's column 
unsigned char decode_row( unsigned char col)
{
    unsigned char mask, row;

    if (col == NO_COLUMN)
        return NO_KEY;  
            
    mask = inp(PIND) & byte(0,0,1,1, 1,1,0,0);
    switch(mask)
    {
    case byte(0,0,1,1, 1,0,0,0):
        row = 2;
        break;
    case byte(0,0,1,1, 0,1,0,0):
        row = 1;
        break;
    case byte(0,0,1,0, 1,0,0,0): //diode effect: two bits low at once
        row = 0;
        break;
    case byte(0,0,0,1, 0,1,0,0): //diode effect: two bits low at once
        row = 3;
        break;
    default: 
        return NO_KEY;
    };
    return keys[row][col];
};

// simple wait loop, compiler and optimization dependant (-Os option used)
void wait(unsigned long delay)
{
    while (delay--)
    {
        #asm("nop");                       //.kbv
    };
};
    
// calibration macro for the above wait loop
#define uS(x)  ( ( (x) * 550L)/1000)

// define sleep macro
//#define sleep()  asm volatile ("sleep" ::)
#define sleep()  #asm("sleep")              //.kbv

// define handlers, just to be safe
SIGNAL(SIG_INT0)
{
};

SIGNAL(SIG_INT1)
{
};


// generate the RF code in the 11 LSB of the parameter
// the code is repeated 15 times
// 270 uS and 550 uS are the times measured on my commercial remote
// control with a fresh battery
void rf_code(unsigned int code)
{
    unsigned int mask;
    unsigned char times;
    
    for (times=0; times < 15; times++)
    {    
        
        // start bit
        RF_ON;
        wait(uS( 270 ));
        
        for (mask = 1 << 11; mask != 0; mask >>= 1)
        {
            RF_OFF;
            if (code & mask)
            {
                //tx 0
                wait( uS(550) );
                RF_ON;
                wait (uS(270) );
            }
            else            
            {    //tx 1
                wait( uS(270) );
                RF_ON;
                wait( uS(550) );
            };
        };
        RF_OFF;    
        wait( uS( 10000));
    };
}
        

void main( void )                 //.kbv
{
       unsigned char key_sequence[ sizeof(COMBINATION_1) ] = "??????";  //be sure this is as long as your combination!
       unsigned char i;                    //used to shift incoming combination string
       
    outp(0xff,PORTB);                       // all pins pulled up on inputs 
    outp(0xff,DDRB);                           // use all pins on PortB for output 

    outp(0xff,PORTD);                       // all pins pulled up on inputs 
    outp(0x00,DDRD);                           // use all pins on PortD for input 
    
    //uart init: enable RxD/TxD and ints, then set baud rate
    outp(( 1<<RXEN)|(1<<TXEN), UCR );       
    outp( (unsigned char) UART_BAUD_SELECT, UBRR );          
    
    //enable sleep, power-down mode, interrupt on low level of either INT0 or INT1
    outp( (1<<SE)|(1<<SM), MCUCR);

    //enable external interrupts
    outp( (1<<INT1)|(1<<INT0), GIMSK);
    
    // tell the world we're alive with a long beep
       wait(400000);
       BEEPER_OFF;
       RF_OFF;
       
       for ( ; ; )
       {    
           
           
        // all keys active
        SEL_COL_ALL;
        wait(10000);

           //wait for the key being released
        while ( key_detected() )
        {
            wait(50000);
        };
        
        //time to go bed! re-enable interrupts and shut off
        sei();
        sleep();
            
           // ...ZZZ...  ...the AVR stays asleep until next keypress...
           
           //key pressed: dummy instruction just to be safe 
           //(some micros skip the instruction next to sleep)
           #asm("nop");                //.kbv
           
           // avoid annoying interrupts until key released
        cli(); 

        //shift combination left, decode key and add it to current combination
        i = 0;
        while( ( key_sequence[i] = key_sequence[i+1]) != 0)
            i++;
        // i points to last character in string
        key_sequence[ i ] = decode_row( find_column() );

        // send key ASCII code to serial port
        outp(key_sequence[ i ], UDR);
    
        // compare combination to valid codes
        // (add here other combinations if needed)
        if ( ! strcmp(key_sequence, COMBINATION_1)    )    
        {
                BEEPER_ON;
                rf_code( codes[1] );    //indirect addressing: see codes[] declaration
                BEEPER_OFF;
           }
           else if ( ! strcmp(key_sequence, COMBINATION_2)    )    
        {
                BEEPER_ON;
                rf_code( codes[2] );
                BEEPER_OFF;
           } 
           else if ( ! strcmp(key_sequence, COMBINATION_3)    )    
        {
                BEEPER_ON;
                rf_code( codes[3] );
                BEEPER_OFF;
           };
           // key beep
           BEEPER_ON;
           wait(15000);
           BEEPER_OFF;
    };
};

Untested.   I have no idea what it is supposed to do.

 

David.

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

I am not familiar with macros - at all - but hopefully I understand assembly.I have a small idea what You have done here:

//.kbv several macros for CV. 
//.kbv Actual Code edits are marked with .kbv
//.kbv note that there is a #warning about codes[3] out of range
#include <string.h>
#define inp(p)    p
#define outp(val, p) p = val
#define sbi(p, b) p |= (1<<(b))
#define cbi(p, b) p &= ~(1<<(b))
#define cli()     #asm("cli")
#define sei()     #asm("sei")
#define SIGNAL(x) interrupt [x] void isr##x(void)
#define SIG_INT0  EXT_INT0
#define SIG_INT1  EXT_INT1

I will try to burn it and try it...

 

 

Thank You !

 

Alex

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

When avr-gcc was first invented,   it was not very good with handling ports etc.

So it came with functions or macros like inp(), outp(), sbi() etc

 

They don't really do anything special.   Modern compilers handle PORTx, PINx etc seamlessly.

 

I notice that you posted exactly the same subject in Jan/Feb 2013.

It looks as if you got exactly the same replies.    e.g. Cliff built it for you.   And pointed out the array bound problem.

i.e. he spent 10-15 minutes of his life in 2013.   I did likewise in 2014.

 

If something does not work properly,   you need to explain it in English.   i.e. what you expected.   what you actually got.

 

It would take a LOT of time for Cliff or I to study the program.

 

David.

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

David Hi !

 

Although I do not understand some makros and why You use them, it is working (Keypad and RS-232 output).You mention that there is a warning message, what is the reason of that ?

 

 

 

Thanks a lot !

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

Exactly the same reason in 2014 as the reason in 2013 when Cliff explained it to you!

 

i.e.  an int array[3] has 3 members: array[0], array[1] and array[2]

 

array[3] would be the 4th member (which has not been allocated)

 

David.

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

Hi, David !

 

 I tested the code.The purpose of that code/circuit is basically a RF remote controller encoder. You must press the correct 6 digit password to activate data transfer.

At this time, it does recognizes all keys of the keypad and sends the relevant ASCII character to RS-232, correctly. But it has an issue.The speed of Tx data is 1/2 of the correct speed.

Ι decided to post it, because I can not understanding why there is that issue even though that you did not change any timer value...

I tried to change the fuse to 8Mhz instead of 4 and then Tx worked correctly and of course ASCII were not o.k.

 

Thank You

Last Edited: Mon. Oct 20, 2014 - 12:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Timing will depend on you actually having a 4MHz crystal.    Which is an unusual value.

Or perhaps you are using the 8MHz RC.   In which case you need to divide by 2 to get 4MHz.    (with CLKPR)

 

And obviously your CV project Configuration needs to be told 4MHz.

 

But the real problem is the Wait() function.

Both CV and GCC would give you 100% precision with delay_us() or delay_ms()

 

Please describe exactly where your problems lie.   e.g. baud rate or the infra-red pulses.

 

David.

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

In brief, clock of μC, is 4Mhz with external crystal. With that value, UART output is o.k, but RF output speed is 50% less than the expected.

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

Well,   all that you have to do is replace the atrocious Wait() function with meaningful delay_us() or delay_ms().

 

Just look at the Wait() function.     It is Bob-special.   i.e. it depends on the compiler,   phase of the moon,   what you eat for breakfast,  ...

 

David.