ATMega2560 and arduino ATMega2560

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

Hye i’m currently working on traffic light with motion sensor project. In proteus simulation i’m using pic ATMega2560 and for the coding i use microC AVR. But when i want to built it hardware, can i change the pic ATMega2560 into arduino ATMega 2560? And how can i change the microC programming into arduino ide? And how can i burn it into arduino? And i’m not a programmer but only a student who knows litlle bit about programming so please help. Tq

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

The Arduino platform is very easy to use and learn, just go to www.arduino.cc  find the software tab and download the IDE for your PC os. 

There are LOTS of examples to learn from and projects to build.

The Mega2560 is found on the Arduino Mega board and should be able to run any thing for it as well as the UNO board.

 

Drop by here if you have specific questions.

Enjoy!

 

Jim

 

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

sntrio wrote:
i’m not a programmer but only a student who knows litlle bit about programming

That, surely, is precisely the intended audience of Arduino?!

 

smiley

 

What subject(s) are you studying?

 

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

I don't know what MicroC is.  But it probably produces K&R C code.  This should run on the GCC++ AVR compiler used by Arduino.

 

Arduino is C++ with a set of standardized downloadable libraries that run common embedded system functions like USART, I2C, push-buttons, TFT displays,  and SPI interfaces.  Arduino splits the main() function into two parts: setup() and loop().  Code that is run once goes into the setup().  Most main() code goes into loop().

 

The Arduino system for AVR focuses on two main ICs: the mega328P and the Mega2560.  These ICs on the Arduino module breakout boards have bootloaders in the flash and USB-serial converter ICs on the board.  Download and load a driver for the USB-serial IC on the Arduino board.  This is usually a CH340G IC and uses the CH341 driver in Windows.  Now you can use the Arduino IDE to send your MIcroC code to the Arduino Mega2560.

 

People use the Arduino Mega2560 when their compilied code is too big to fit into a Mega328P (above about 29-30K bytes in size), or, they need more RAM, Input/output pins, or serial ports than the mega328P, or they want to use external data/address buses (with an ALE strobe) to access external memory directly by the microcontroller, or they have a TFT controller that specifically uses the Mega2560 Arduino pinout.  If these criteria don't apply to your application, then I suggest using the Arduino Nano/UNO instead.  It's cheaper, faster, and easier to work with.
 

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

an i change the pic ATMega2560

Not a pic but an AVR...just being picky...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

sntrio wrote:
ATMega2560 and for the coding i use microC AVR.

 

Are you using the demo version of MikroC or did you purchase the license?  The demo version only works with devices with 4k of flash or less.

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

HYe, how can i burn microC avr coding into arduino without using the arduino ide? Could you help me? and here also my email sn.trio97@gmail.com

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

i'm studying electrical engineer and working on my final year project for traffic light using arduino mega 2560. My coding is in microC avr but i'm using its .hex file for arduino. So how can i burn the coding into  my arduino hardware? what bootloader does i need to use? 

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

sntrio wrote:
Hye i’m currently working on traffic light with motion sensor project. In proteus simulation i’m using pic ATMega2560 and for the coding i use microC AVR. But when i want to built it hardware, can i change the pic ATMega2560 into arduino ATMega 2560? And how can i change the microC programming into arduino ide? And how can i burn it into arduino? And i’m not a programmer but only a student who knows litlle bit about programming so please help. Tq

 

Can anyone convert my MicroC avr coding into Arduino IDE coding?

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

If you have the Arduino IDE installed on your PC, then you have AVRdude, and can use it to load your hex file.

I'm sure another freak will give you the command line details to make that happen.

 

Jim

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

Simonetta wrote:
I don't know what MicroC is. But it probably produces K&R C code.
Sadly that is not true. MikroC is utterly terrible. It cannot really claim to be a "C compiler" as it does not support the C language properly. If it actually managed to compile some K&R compliant code we'd probably all put it in a glass case and throw sugar at it!

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

Hye i'm having problem uloading my coding into arduino. I'm using MegunoLink to upload but then my project did not run the coding. I already check my hardware for all possible fault in wiring but it still didnt work. Could someone take a look for my project?

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

Why don't you just use the Arduino IDE that "just works" for everyone?

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

Well, unless you have microelectonica libraries, you can paste microC code into the arduino, then getting it compiled.

Arduino IDE is free (maybe it is not the best), you can get a lot of help through examples. If carefully configured, it is very easy to upload an arduino...

Maybe the best thing you might do would be to ... post the microC code you wrote (if posted between < and > in this forum menu -the penultimate item...- , it might be pleasant to read: then, one might know whether it is difficult to convert it into standard c, and if there are  better things with Arduino.

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

ok thank you i'll try it

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

because my coding is in micro C pro avr so its in C language and i didnt know how to  change into arduino coding format for the arduino ide. but if someone could help it would be helpful

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

dbrion0606 wrote:
post the microC code you wrote (if posted between < and > in this forum menu -the penultimate item...

Illustrated instructions here: http://www.avrfreaks.net/comment...

 

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

because my coding is in micro C pro avr so its in C language and i didnt know how to  change into arduino coding format for the arduino ide. but if someone could help it would be helpful

IIRC, microC looks like C and there wonot be huge editing. The "only" thing that worries me is that they are likely to use their own libraries. The only way to get an accurate answer is:

to copy what you wrote , then paste it into this forum.

 

As a first approximation, arduino language ...is simplified C++ -this is not an approximation) and C++ is almost compatible with C (you can paste C code into a C++ program, and g++ will compile it : it is ugly, people can see it is ugly, modern g++ compilers will protest because it is ugly,  but I -and many others-  never run into trouble with such approximations; else, g++ can call plain c routines, but that makes arduino projects more complicated).

 

Then, if you do not use too many mikroelectronica - specific libraries (setting up pins and reading switches is not a huge library), porting to Arduino is not terrible (I hope there are some comments..)

 

The only way to get some help is to post (parts of)  your code (else, this remains very vague and abstract), unless it is top secret copyrighted...

.

 

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

#define Max_Junctions 4

#define Junction_1 0
#define Junction_2 1
#define Junction_3 2
#define Junction_4 3

#define Traffic_Light_Counter_Data_Port PORTA
#define Traffic_Light_Control_Port      PORTC
#define Traffic_Light_Data_Port         PORTF
#define Horn_Port                       PORTK

#define Red_Light    0x01
#define Yellow_Light 0x02
#define Green_Light  0x04

const unsigned char cc_mask[11] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
char i = 0;

typedef struct {
  unsigned char display[4];
  unsigned char traffic_light_data[4];
  unsigned char counters[4];
  unsigned char previous_counters[4];
  unsigned char selected_display;
  unsigned char max_junctions;
  int one_second_delay_counter;
  int one_second_delay_count;
  unsigned char active_traffic_light[4];
  unsigned char heavy_traffic_flag[4];
} TRAFFIC_LIGHTS_CONTROL_TYPE;

TRAFFIC_LIGHTS_CONTROL_TYPE my_traffic_light_system;

unsigned char Load_Red_Signal_Counter_Value() {
    return ( 0 );
}

unsigned char Load_Yellow_Signal_Counter_Value() {
    return ( 3 );
}

unsigned char Load_Green_Signal_Counter_Value() {
    return ( 7 );
}

unsigned char Load_Blank_Value_For_Display() {
    return ( 0x40 );
}

unsigned char Set_Active_Traffic_Light() {
     return ( 1 );
}

unsigned char Set_Inactive_Traffic_Light() {
     return ( 0 );
}

int Set_One_Second_Delay_Count_Value() {
    return ( 50 );
}

int Reset_One_Second_Delay_Counter_Value() {
    return ( 0 );
}

unsigned char Set_Traffic_Light_To_Red() {
    return ( 1 );
}

unsigned char Set_Traffic_Light_To_Yellow() {
    return ( 2 );
}

unsigned char Set_Traffic_Light_To_Green() {
    return ( 4 );
}

unsigned char Set_Heavy_Traffic_Flag() {
    return ( 1 );
}

unsigned char Clear_Heavy_Traffic_Flag() {
    return ( 0 );
}

unsigned char Set_Heavy_Traffic_Delay() {
    return ( 9 );
}

//Timer1 Prescaler = 0; Preload = 31999; Actual Interrupt Time = 2 ms
void InitTimer1() {
    SREG_I_bit = 1;
    TCCR1A = 0x00;
    TCCR1B = 0x09;
    OCR1AH = 0x7C;
    OCR1AL = 0xFF;
    OCIE1A_bit = 1;
}

void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA {
    //Enter your code here
    Traffic_Light_Control_Port &= 0xF0;
    Traffic_Light_Data_Port &= 0xF8;

    switch(my_traffic_light_system.selected_display) {
          case Junction_1:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[0];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[0];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x08;
                         break;
          case Junction_2:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[1];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[1];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x04;
                         break;
          case Junction_3:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[2];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[2];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x02;
                         break;
          case Junction_4:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[3];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[3];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x01;
                         break;

    };

    if(++my_traffic_light_system.selected_display >= my_traffic_light_system.max_junctions) {
        my_traffic_light_system.selected_display = Junction_1;
    }

    if(++my_traffic_light_system.one_second_delay_counter >= my_traffic_light_system.one_second_delay_count) {
        if(my_traffic_light_system.active_traffic_light[i] == 1) {
            if((my_traffic_light_system.counters[i] > 0)
               && (my_traffic_light_system.traffic_light_data[i] == Green_Light)) {
                --my_traffic_light_system.counters[i];
            }

            if((my_traffic_light_system.counters[i] > 0)
               && (my_traffic_light_system.traffic_light_data[i] == Yellow_Light)) {
                --my_traffic_light_system.counters[i];
            }

            if((my_traffic_light_system.counters[i] == 0)
               && (my_traffic_light_system.traffic_light_data[i] == Yellow_Light)) {
                Horn_Port = 0x00;

                if(my_traffic_light_system.heavy_traffic_flag[i] == 1) {
                    my_traffic_light_system.heavy_traffic_flag[i] = Clear_Heavy_Traffic_Flag();
                    my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value() + 2;
                }
                else {
                    my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value();
                }

                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Red();
                my_traffic_light_system.display[i] = Load_Blank_Value_For_Display();
                my_traffic_light_system.active_traffic_light[i] = Set_Inactive_Traffic_Light();

                if(++i >= Max_Junctions) {
                   i = 0;
                }

                my_traffic_light_system.active_traffic_light[i] = Set_Active_Traffic_Light();

                if(my_traffic_light_system.counters[i] == 0) {
                   my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value();
                }

                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Green();
            }

            if((my_traffic_light_system.counters[i] == 0)
               && (my_traffic_light_system.traffic_light_data[i] == Green_Light)) {
                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Yellow();
                my_traffic_light_system.counters[i] = Load_Yellow_Signal_Counter_Value();

                switch(i) {
                   case 0:
                          Horn_Port = 0x01;
                          break;
                   case 1:
                          Horn_Port = 0x02;
                          break;
                   case 2:
                          Horn_Port = 0x04;
                          break;
                   case 3:
                          Horn_Port = 0x08;
                          break;

                };
            }

            my_traffic_light_system.display[i] = cc_mask[my_traffic_light_system.counters[i]];
        }

        my_traffic_light_system.one_second_delay_counter = 0;
    }
}

void EXT_Int0() iv IVT_ADDR_INT0 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[0] == 1)
      && (my_traffic_light_system.traffic_light_data[0] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[0] = Set_Heavy_Traffic_Flag();
    }

    PORTK7_bit = ~PORTK7_bit;
}

void EXT_Int1() iv IVT_ADDR_INT1 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[1] == 1)
      && (my_traffic_light_system.traffic_light_data[1] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[1] = Set_Heavy_Traffic_Flag();
    }
}

void EXT_Int2() iv IVT_ADDR_INT2 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[2] == 1)
      && (my_traffic_light_system.traffic_light_data[2] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[2] = Set_Heavy_Traffic_Flag();
    }
}

void EXT_Int3() iv IVT_ADDR_INT3 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[3] == 1)
      && (my_traffic_light_system.traffic_light_data[3] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[3] = Set_Heavy_Traffic_Flag();
    }
}

void Initialize_Traffic_Light_System() {
    my_traffic_light_system.active_traffic_light[0] = Set_Active_Traffic_Light();
    my_traffic_light_system.active_traffic_light[1] = Set_Inactive_Traffic_Light();
    my_traffic_light_system.active_traffic_light[2] = Set_Inactive_Traffic_Light();
    my_traffic_light_system.active_traffic_light[3] = Set_Inactive_Traffic_Light();

    my_traffic_light_system.display[0] = cc_mask[Load_Green_Signal_Counter_Value()];
    my_traffic_light_system.display[1] = Load_Blank_Value_For_Display();
    my_traffic_light_system.display[2] = Load_Blank_Value_For_Display();
    my_traffic_light_system.display[3] = Load_Blank_Value_For_Display();

    my_traffic_light_system.one_second_delay_count = Set_One_Second_Delay_Count_Value();
    my_traffic_light_system.one_second_delay_counter = Reset_One_Second_Delay_Counter_Value();

    my_traffic_light_system.selected_display = 0;

    my_traffic_light_system.traffic_light_data[0] = Set_Traffic_Light_To_Green();
    my_traffic_light_system.traffic_light_data[1] = Set_Traffic_Light_To_Red();
    my_traffic_light_system.traffic_light_data[2] = Set_Traffic_Light_To_Red();
    my_traffic_light_system.traffic_light_data[3] = Set_Traffic_Light_To_Red();

    my_traffic_light_system.counters[0] = Load_Green_Signal_Counter_Value();
    my_traffic_light_system.counters[1] = Load_Red_Signal_Counter_Value();
    my_traffic_light_system.counters[2] = Load_Red_Signal_Counter_Value();
    my_traffic_light_system.counters[3] = Load_Red_Signal_Counter_Value();

    my_traffic_light_system.max_junctions = Max_Junctions;

    my_traffic_light_system.heavy_traffic_flag[0] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[1] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[2] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[3] = Clear_Heavy_Traffic_Flag();

    Horn_Port = 0x00;

    EICRB = ( 1 << ISC30 ) | ( 1 << ISC20 ) | ( 1 << ISC10 )|( 1 << ISC00 );
    EIMSK = ( 1 << INT3 ) | ( 1 << INT2 ) | ( 1 << INT1 ) | ( 1 << INT0 );

    InitTimer1();
}

void main() {

    DDRA = 0xFF;
    DDRC = 0x0F;
    DDRD = 0x00;
    DDRF = 0x07;
    DDRK = 0xFF;

    PORTA = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    PORTF = 0x00;
    PORTK = 0x00;

    Delay_ms(100);

    Initialize_Traffic_Light_System();

    while(1) {

    }
}

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

sntrio wrote:

#define Max_Junctions 4

#define Junction_1 0
#define Junction_2 1
#define Junction_3 2
#define Junction_4 3

#define Traffic_Light_Counter_Data_Port PORTA
#define Traffic_Light_Control_Port      PORTC
#define Traffic_Light_Data_Port         PORTF
#define Horn_Port                       PORTK

#define Red_Light    0x01
#define Yellow_Light 0x02
#define Green_Light  0x04

const unsigned char cc_mask[11] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
char i = 0;

typedef struct {
  unsigned char display[4];
  unsigned char traffic_light_data[4];
  unsigned char counters[4];
  unsigned char previous_counters[4];
  unsigned char selected_display;
  unsigned char max_junctions;
  int one_second_delay_counter;
  int one_second_delay_count;
  unsigned char active_traffic_light[4];
  unsigned char heavy_traffic_flag[4];
} TRAFFIC_LIGHTS_CONTROL_TYPE;

TRAFFIC_LIGHTS_CONTROL_TYPE my_traffic_light_system;

unsigned char Load_Red_Signal_Counter_Value() {
    return ( 0 );
}

unsigned char Load_Yellow_Signal_Counter_Value() {
    return ( 3 );
}

unsigned char Load_Green_Signal_Counter_Value() {
    return ( 7 );
}

unsigned char Load_Blank_Value_For_Display() {
    return ( 0x40 );
}

unsigned char Set_Active_Traffic_Light() {
     return ( 1 );
}

unsigned char Set_Inactive_Traffic_Light() {
     return ( 0 );
}

int Set_One_Second_Delay_Count_Value() {
    return ( 50 );
}

int Reset_One_Second_Delay_Counter_Value() {
    return ( 0 );
}

unsigned char Set_Traffic_Light_To_Red() {
    return ( 1 );
}

unsigned char Set_Traffic_Light_To_Yellow() {
    return ( 2 );
}

unsigned char Set_Traffic_Light_To_Green() {
    return ( 4 );
}

unsigned char Set_Heavy_Traffic_Flag() {
    return ( 1 );
}

unsigned char Clear_Heavy_Traffic_Flag() {
    return ( 0 );
}

unsigned char Set_Heavy_Traffic_Delay() {
    return ( 9 );
}

//Timer1 Prescaler = 0; Preload = 31999; Actual Interrupt Time = 2 ms
void InitTimer1() {
    SREG_I_bit = 1;
    TCCR1A = 0x00;
    TCCR1B = 0x09;
    OCR1AH = 0x7C;
    OCR1AL = 0xFF;
    OCIE1A_bit = 1;
}

void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA {
    //Enter your code here
    Traffic_Light_Control_Port &= 0xF0;
    Traffic_Light_Data_Port &= 0xF8;

    switch(my_traffic_light_system.selected_display) {
          case Junction_1:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[0];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[0];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x08;
                         break;
          case Junction_2:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[1];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[1];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x04;
                         break;
          case Junction_3:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[2];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[2];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x02;
                         break;
          case Junction_4:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[3];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[3];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x01;
                         break;

    };

    if(++my_traffic_light_system.selected_display >= my_traffic_light_system.max_junctions) {
        my_traffic_light_system.selected_display = Junction_1;
    }

    if(++my_traffic_light_system.one_second_delay_counter >= my_traffic_light_system.one_second_delay_count) {
        if(my_traffic_light_system.active_traffic_light[i] == 1) {
            if((my_traffic_light_system.counters[i] > 0)
               && (my_traffic_light_system.traffic_light_data[i] == Green_Light)) {
                --my_traffic_light_system.counters[i];
            }

            if((my_traffic_light_system.counters[i] > 0)
               && (my_traffic_light_system.traffic_light_data[i] == Yellow_Light)) {
                --my_traffic_light_system.counters[i];
            }

            if((my_traffic_light_system.counters[i] == 0)
               && (my_traffic_light_system.traffic_light_data[i] == Yellow_Light)) {
                Horn_Port = 0x00;

                if(my_traffic_light_system.heavy_traffic_flag[i] == 1) {
                    my_traffic_light_system.heavy_traffic_flag[i] = Clear_Heavy_Traffic_Flag();
                    my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value() + 2;
                }
                else {
                    my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value();
                }

                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Red();
                my_traffic_light_system.display[i] = Load_Blank_Value_For_Display();
                my_traffic_light_system.active_traffic_light[i] = Set_Inactive_Traffic_Light();

                if(++i >= Max_Junctions) {
                   i = 0;
                }

                my_traffic_light_system.active_traffic_light[i] = Set_Active_Traffic_Light();

                if(my_traffic_light_system.counters[i] == 0) {
                   my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value();
                }

                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Green();
            }

            if((my_traffic_light_system.counters[i] == 0)
               && (my_traffic_light_system.traffic_light_data[i] == Green_Light)) {
                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Yellow();
                my_traffic_light_system.counters[i] = Load_Yellow_Signal_Counter_Value();

                switch(i) {
                   case 0:
                          Horn_Port = 0x01;
                          break;
                   case 1:
                          Horn_Port = 0x02;
                          break;
                   case 2:
                          Horn_Port = 0x04;
                          break;
                   case 3:
                          Horn_Port = 0x08;
                          break;

                };
            }

            my_traffic_light_system.display[i] = cc_mask[my_traffic_light_system.counters[i]];
        }

        my_traffic_light_system.one_second_delay_counter = 0;
    }
}

void EXT_Int0() iv IVT_ADDR_INT0 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[0] == 1)
      && (my_traffic_light_system.traffic_light_data[0] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[0] = Set_Heavy_Traffic_Flag();
    }

    PORTK7_bit = ~PORTK7_bit;
}

void EXT_Int1() iv IVT_ADDR_INT1 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[1] == 1)
      && (my_traffic_light_system.traffic_light_data[1] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[1] = Set_Heavy_Traffic_Flag();
    }
}

void EXT_Int2() iv IVT_ADDR_INT2 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[2] == 1)
      && (my_traffic_light_system.traffic_light_data[2] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[2] = Set_Heavy_Traffic_Flag();
    }
}

void EXT_Int3() iv IVT_ADDR_INT3 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[3] == 1)
      && (my_traffic_light_system.traffic_light_data[3] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[3] = Set_Heavy_Traffic_Flag();
    }
}

void Initialize_Traffic_Light_System() {
    my_traffic_light_system.active_traffic_light[0] = Set_Active_Traffic_Light();
    my_traffic_light_system.active_traffic_light[1] = Set_Inactive_Traffic_Light();
    my_traffic_light_system.active_traffic_light[2] = Set_Inactive_Traffic_Light();
    my_traffic_light_system.active_traffic_light[3] = Set_Inactive_Traffic_Light();

    my_traffic_light_system.display[0] = cc_mask[Load_Green_Signal_Counter_Value()];
    my_traffic_light_system.display[1] = Load_Blank_Value_For_Display();
    my_traffic_light_system.display[2] = Load_Blank_Value_For_Display();
    my_traffic_light_system.display[3] = Load_Blank_Value_For_Display();

    my_traffic_light_system.one_second_delay_count = Set_One_Second_Delay_Count_Value();
    my_traffic_light_system.one_second_delay_counter = Reset_One_Second_Delay_Counter_Value();

    my_traffic_light_system.selected_display = 0;

    my_traffic_light_system.traffic_light_data[0] = Set_Traffic_Light_To_Green();
    my_traffic_light_system.traffic_light_data[1] = Set_Traffic_Light_To_Red();
    my_traffic_light_system.traffic_light_data[2] = Set_Traffic_Light_To_Red();
    my_traffic_light_system.traffic_light_data[3] = Set_Traffic_Light_To_Red();

    my_traffic_light_system.counters[0] = Load_Green_Signal_Counter_Value();
    my_traffic_light_system.counters[1] = Load_Red_Signal_Counter_Value();
    my_traffic_light_system.counters[2] = Load_Red_Signal_Counter_Value();
    my_traffic_light_system.counters[3] = Load_Red_Signal_Counter_Value();

    my_traffic_light_system.max_junctions = Max_Junctions;

    my_traffic_light_system.heavy_traffic_flag[0] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[1] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[2] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[3] = Clear_Heavy_Traffic_Flag();

    Horn_Port = 0x00;

    EICRB = ( 1 << ISC30 ) | ( 1 << ISC20 ) | ( 1 << ISC10 )|( 1 << ISC00 );
    EIMSK = ( 1 << INT3 ) | ( 1 << INT2 ) | ( 1 << INT1 ) | ( 1 << INT0 );

    InitTimer1();
}

void main() {

    DDRA = 0xFF;
    DDRC = 0x0F;
    DDRD = 0x00;
    DDRF = 0x07;
    DDRK = 0xFF;

    PORTA = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    PORTF = 0x00;
    PORTK = 0x00;

    Delay_ms(100);

    Initialize_Traffic_Light_System();

    while(1) {

    }
}

here is my coding.. so how can i change into arduino ide coding?

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

Now go back to #14 and #17 and read the instructions on how to post source code!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define Max_Junctions 4

#define Junction_1 0
#define Junction_2 1
#define Junction_3 2
#define Junction_4 3

#define Traffic_Light_Counter_Data_Port PORTA
#define Traffic_Light_Control_Port      PORTC
#define Traffic_Light_Data_Port         PORTF
#define Horn_Port                       PORTK

#define Red_Light    0x01
#define Yellow_Light 0x02
#define Green_Light  0x04

const unsigned char cc_mask[11] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
char i = 0;

typedef struct {
  unsigned char display[4];
  unsigned char traffic_light_data[4];
  unsigned char counters[4];
  unsigned char previous_counters[4];
  unsigned char selected_display;
  unsigned char max_junctions;
  int one_second_delay_counter;
  int one_second_delay_count;
  unsigned char active_traffic_light[4];
  unsigned char heavy_traffic_flag[4];
} TRAFFIC_LIGHTS_CONTROL_TYPE;

TRAFFIC_LIGHTS_CONTROL_TYPE my_traffic_light_system;

unsigned char Load_Red_Signal_Counter_Value() {
    return ( 0 );
}

unsigned char Load_Yellow_Signal_Counter_Value() {
    return ( 3 );
}

unsigned char Load_Green_Signal_Counter_Value() {
    return ( 7 );
}

unsigned char Load_Blank_Value_For_Display() {
    return ( 0x40 );
}

unsigned char Set_Active_Traffic_Light() {
     return ( 1 );
}

unsigned char Set_Inactive_Traffic_Light() {
     return ( 0 );
}

int Set_One_Second_Delay_Count_Value() {
    return ( 50 );
}

int Reset_One_Second_Delay_Counter_Value() {
    return ( 0 );
}

unsigned char Set_Traffic_Light_To_Red() {
    return ( 1 );
}

unsigned char Set_Traffic_Light_To_Yellow() {
    return ( 2 );
}

unsigned char Set_Traffic_Light_To_Green() {
    return ( 4 );
}

unsigned char Set_Heavy_Traffic_Flag() {
    return ( 1 );
}

unsigned char Clear_Heavy_Traffic_Flag() {
    return ( 0 );
}

unsigned char Set_Heavy_Traffic_Delay() {
    return ( 9 );
}

//Timer1 Prescaler = 0; Preload = 31999; Actual Interrupt Time = 2 ms
void InitTimer1() {
    SREG_I_bit = 1;
    TCCR1A = 0x00;
    TCCR1B = 0x09;
    OCR1AH = 0x7C;
    OCR1AL = 0xFF;
    OCIE1A_bit = 1;
}

void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA {
    //Enter your code here
    Traffic_Light_Control_Port &= 0xF0;
    Traffic_Light_Data_Port &= 0xF8;

    switch(my_traffic_light_system.selected_display) {
          case Junction_1:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[0];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[0];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x08;
                         break;
          case Junction_2:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[1];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[1];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x04;
                         break;
          case Junction_3:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[2];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[2];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x02;
                         break;
          case Junction_4:
                         Traffic_Light_Counter_Data_Port = my_traffic_light_system.display[3];
                         Traffic_Light_Data_Port = (Traffic_Light_Data_Port & 0xF8)
                              | my_traffic_light_system.traffic_light_data[3];
                         Traffic_Light_Control_Port = (Traffic_Light_Control_Port & 0xF0) | 0x01;
                         break;

    };

    if(++my_traffic_light_system.selected_display >= my_traffic_light_system.max_junctions) {
        my_traffic_light_system.selected_display = Junction_1;
    }

    if(++my_traffic_light_system.one_second_delay_counter >= my_traffic_light_system.one_second_delay_count) {
        if(my_traffic_light_system.active_traffic_light[i] == 1) {
            if((my_traffic_light_system.counters[i] > 0)
               && (my_traffic_light_system.traffic_light_data[i] == Green_Light)) {
                --my_traffic_light_system.counters[i];
            }

            if((my_traffic_light_system.counters[i] > 0)
               && (my_traffic_light_system.traffic_light_data[i] == Yellow_Light)) {
                --my_traffic_light_system.counters[i];
            }

            if((my_traffic_light_system.counters[i] == 0)
               && (my_traffic_light_system.traffic_light_data[i] == Yellow_Light)) {
                Horn_Port = 0x00;

                if(my_traffic_light_system.heavy_traffic_flag[i] == 1) {
                    my_traffic_light_system.heavy_traffic_flag[i] = Clear_Heavy_Traffic_Flag();
                    my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value() + 2;
                }
                else {
                    my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value();
                }

                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Red();
                my_traffic_light_system.display[i] = Load_Blank_Value_For_Display();
                my_traffic_light_system.active_traffic_light[i] = Set_Inactive_Traffic_Light();

                if(++i >= Max_Junctions) {
                   i = 0;
                }

                my_traffic_light_system.active_traffic_light[i] = Set_Active_Traffic_Light();

                if(my_traffic_light_system.counters[i] == 0) {
                   my_traffic_light_system.counters[i] = Load_Green_Signal_Counter_Value();
                }

                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Green();
            }

            if((my_traffic_light_system.counters[i] == 0)
               && (my_traffic_light_system.traffic_light_data[i] == Green_Light)) {
                my_traffic_light_system.traffic_light_data[i] = Set_Traffic_Light_To_Yellow();
                my_traffic_light_system.counters[i] = Load_Yellow_Signal_Counter_Value();

                switch(i) {
                   case 0:
                          Horn_Port = 0x01;
                          break;
                   case 1:
                          Horn_Port = 0x02;
                          break;
                   case 2:
                          Horn_Port = 0x04;
                          break;
                   case 3:
                          Horn_Port = 0x08;
                          break;

                };
            }

            my_traffic_light_system.display[i] = cc_mask[my_traffic_light_system.counters[i]];
        }

        my_traffic_light_system.one_second_delay_counter = 0;
    }
}

void EXT_Int0() iv IVT_ADDR_INT0 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[0] == 1)
      && (my_traffic_light_system.traffic_light_data[0] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[0] = Set_Heavy_Traffic_Flag();
    }

    PORTK7_bit = ~PORTK7_bit;
}

void EXT_Int1() iv IVT_ADDR_INT1 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[1] == 1)
      && (my_traffic_light_system.traffic_light_data[1] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[1] = Set_Heavy_Traffic_Flag();
    }
}

void EXT_Int2() iv IVT_ADDR_INT2 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[2] == 1)
      && (my_traffic_light_system.traffic_light_data[2] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[2] = Set_Heavy_Traffic_Flag();
    }
}

void EXT_Int3() iv IVT_ADDR_INT3 ics ICS_AUTO {
    if((my_traffic_light_system.active_traffic_light[3] == 1)
      && (my_traffic_light_system.traffic_light_data[3] == 0x04)) {
       my_traffic_light_system.heavy_traffic_flag[3] = Set_Heavy_Traffic_Flag();
    }
}

void Initialize_Traffic_Light_System() {
    my_traffic_light_system.active_traffic_light[0] = Set_Active_Traffic_Light();
    my_traffic_light_system.active_traffic_light[1] = Set_Inactive_Traffic_Light();
    my_traffic_light_system.active_traffic_light[2] = Set_Inactive_Traffic_Light();
    my_traffic_light_system.active_traffic_light[3] = Set_Inactive_Traffic_Light();

    my_traffic_light_system.display[0] = cc_mask[Load_Green_Signal_Counter_Value()];
    my_traffic_light_system.display[1] = Load_Blank_Value_For_Display();
    my_traffic_light_system.display[2] = Load_Blank_Value_For_Display();
    my_traffic_light_system.display[3] = Load_Blank_Value_For_Display();

    my_traffic_light_system.one_second_delay_count = Set_One_Second_Delay_Count_Value();
    my_traffic_light_system.one_second_delay_counter = Reset_One_Second_Delay_Counter_Value();

    my_traffic_light_system.selected_display = 0;

    my_traffic_light_system.traffic_light_data[0] = Set_Traffic_Light_To_Green();
    my_traffic_light_system.traffic_light_data[1] = Set_Traffic_Light_To_Red();
    my_traffic_light_system.traffic_light_data[2] = Set_Traffic_Light_To_Red();
    my_traffic_light_system.traffic_light_data[3] = Set_Traffic_Light_To_Red();

    my_traffic_light_system.counters[0] = Load_Green_Signal_Counter_Value();
    my_traffic_light_system.counters[1] = Load_Red_Signal_Counter_Value();
    my_traffic_light_system.counters[2] = Load_Red_Signal_Counter_Value();
    my_traffic_light_system.counters[3] = Load_Red_Signal_Counter_Value();

    my_traffic_light_system.max_junctions = Max_Junctions;

    my_traffic_light_system.heavy_traffic_flag[0] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[1] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[2] = Clear_Heavy_Traffic_Flag();
    my_traffic_light_system.heavy_traffic_flag[3] = Clear_Heavy_Traffic_Flag();

    Horn_Port = 0x00;

    EICRB = ( 1 << ISC30 ) | ( 1 << ISC20 ) | ( 1 << ISC10 )|( 1 << ISC00 );
    EIMSK = ( 1 << INT3 ) | ( 1 << INT2 ) | ( 1 << INT1 ) | ( 1 << INT0 );

    InitTimer1();
}

void main() {

    DDRA = 0xFF;
    DDRC = 0x0F;
    DDRD = 0x00;
    DDRF = 0x07;
    DDRK = 0xFF;

    PORTA = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    PORTF = 0x00;
    PORTK = 0x00;

    Delay_ms(100);

    Initialize_Traffic_Light_System();

    while(1) {

    }
}

Well, your code can be put into this forums beautifier... that is not desesparate.

The sequence :

{ setting registers;waiting 100 ms;

InitializeTrafficLightSystem }can be renamed as setup (it is the name one should give to the init routine); Delay_ms becomes delay (Arduino library)

 

Other compulsory routine name "loop"  can be void (it replaces while (1), as you "only" use interrupts.

Bit designation is very different... but there are not that many lines.

You should explain, as comment, how lights are wired -else, it is very difficult to guess what your code does-

 

-> porting can be tedious, but can be done IMO, except for the ISR

 

Remain all the ISR... but it is somewhat late in my country and there are things I do not understand -leading to worse than doing nothing if I attempted correcting- :

 

void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA  // I might misunderstand "org" and "IVT_ADDR-TIMER_COMPA"

 

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

What is the point of all those functions which do nothing but return a constant value??

 

has this been auto-generated by some tool ?

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

These functions could be declared as inline (would eat less flash/RAM), or ... as constants (or as macros, which is sometimes felt as ugly).

They are not annoying for code coversion into arduino g++ (or plain gcc).

 

The most difficult part is that there are a lot of interrupts (timer + sensor) and no main, except for initializing.

This makes choosing between:

* keeping the structure, with a lot of interrupts

*writing a loopn which looks at the sensors, if necessary changes the lights, then looks how much time elapsed since last light change, and if necessary changes the light (does not need any interrupt at all, as Arduino has a millis() function and changing the ports states is very fast)

* use Arduino's avrdude to upload microC generated binary (the way I would do it would be : a) to activate verbose output when uploading : this is configuration of Arduino b)write / copy and paste its settings c) use this settings as a command line to upload binary. This is the fastest solution, but the issue with microC is it is not as general/popular as gcc/g++ ...

 

I bet proteus supports arduino/gcc code...

 

There are other questions ;

is OP a student/a hobbyist (I bet it is not his job : arduino is not that popular in the industrial world). A student might get help rereading his courses (....) and asking his teachers. A hobbyist can be more isolated.

 

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

dbrion0606 wrote:
There are other questions ;

is OP a student

(S)he says (s)he is:

sntrio wrote:
i’m not a programmer but only a student 

sntrio wrote:
i'm studying electrical engineer and working on my final year project 

 

dbrion0606 wrote:
A student might get help rereading his courses (....) and asking his teachers

Why does that never seem to occur to "students" these days??

 

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

Perhaps teachers are deaf... or made a bad choice advising microC (does not exist outside microcontroller world; standard C is more advisable on the long term; port to gcc seem  somewhat complicated), leading to untrust.

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

dbrion0606 wrote:
standard C is more advisable on the long term; port to gcc seem  somewhat complicated

Does it?

 

It looks pretty straightforward to me - just the change of syntax for the ISRs.

 

(Standard 'C' knows nothing of ISRs - so any support is always going to be by proprietary extensions).

 

 

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

Depends on the "definition" -rather subjective notion  of complexity (for a beginner, who wrote a simulated working code; at local 10 pm... for me) .

 

Changing the syntax for the ISR may be complicated for a student (I agree there are "only" 5 ISR declarations  invocations).

As far as I could see, IAR -I read some examples- and avr/arm -gcc ISR declarations are easy to understand and very similar; microC ones are not...

 

Anyway, it seems very tedious (and, BTW : it is the first time I have to write variable names are too long, underscored whitespace is difficult to see whith aging eyes : light_to_change, say, is more difficult to read than lightToChange)

 

Maybe, using Arduino's built in timer , one does not need interrupts at all (just polling elapsed time from the beginning and sensor pins; advantages Arduino has its own interrupts and one does not need to see whether there will be an interference with user interrupts : ex : OPs code does not use time0 timer0,  and it is lucky, as Arduino's  millis() uses it), but it would need some rewriting -and changing the structure-.

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

Fyi i already ask my supervisor(lecturer) to help on my project but eventually she's not teaching programming and didnt know nothing about pic and arduino. So i have to figure it all by myself 

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

Thank you but  i did not do all the coding myself as someone help me and simplify my coding to my understanding. But now how can i change it into arduino ide coding?

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

dbrion0606 wrote:
Changing the syntax for the ISR may be complicated for a student 

It shouldn't be - especially for a final year student!

 

It's just a 1-line change (and repeated for each ISR). You just need to look at a trivial GCC example to see the pattern.

 

Apart from that, it looks like the code should compile as-is.

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

sntrio wrote:
Fyi i already ask my supervisor(lecturer) to help on my project but eventually she's not teaching programming and didnt know nothing about pic and arduino. So i have to figure it all by myself 

sntrio wrote:
Thank you but  i did not do all the coding myself as someone help me and simplify my coding to my understanding.

 

That's bizarre!

 

The whole point of a final year project is to demonstrate what you have learned in your course; so why did you choose a project which so clearly relies upon something you know nothing about?

Did you not discuss this with your tutor - to ensure that it was an appropriate & achievable project - before you started?

 

Anyhow, surely there must be other teachers available who can help you with this?

 

Or go back to whoever "helped" you with the code initially?

 

But now how can i change it into arduino ide coding?

I think the easiest thing would probably be to start again from scratch.

 

Controlling traffic lights is usually a beginner example in programming classes - so you should be able to find plenty of stuff online

 

http://www.lmgtfy.com?q=traffic+light+Arduino

 

 

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

okay thanks for your help.

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

ATMega 324PB, 168, 168PB, 328P, and 328PB are all available on XPlained (Pro or Mini) boards:

 

http://www.atmel.com/products/mi...

 

These have a built-in programmer & debugger - so there would be nothing else to buy or configure.

 

The boards will be recognised by Atmel Studio, which will present you with ready-made examples.

 

So you should quickly be able to see how to do interrupts in GCC.

 

As noted above, I think that should be the only change needed to your code ...

 

(Atmel Studio does have a simulator - so you could try it for free, without buying any hardware).

 

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

As far as I could understand : OP is studying electrical engineering -> computer science| microinformatics is a (small, but it is likely to become more and more important) part of what (s)he needs to know : I knew of o electrical engineering teacher, in a small French province town, who wanted to learn c++ : he was told one could find Hackable Magazine at the railway station (200 meters), with very good examples of Arduino codes, thoroughly commenetd... and buy an Arduino at the electronics part seller, 300 meters away, to practice. This was the easiest way I could find to teach oneself C++, and , in the wide world, electrical engeneering teachers maybe worse in microinformatics than in my small provincial french town....

 

Apart from starting from scratch (OP's (friends) codes manages horns and  emergency buttons, which makes it rather interesting) or making it arduino specific (but code lacks comments)  maybe  :

 

* OP should download the arduino software, configure it for the mega25560, become acquainted with its help and some examples (look at least at the minimalist one -6 lines : gives a very nice skeleton- , the blink one and the blink_without_delay one) and configure the IDE to have verbose messages when compiling and uploading (this is a lazy way of getting avrdude's invocation if (s)he "only" wants to upload existing microC generated code, other solution involve ... reading avrdude manual or letting the mightly google find some kind of help). As nobody has telescopic arms (at least, they are not long enough), only OP can do it.

 

* there are 5 lines -ISR "invocations"- which are complicated IMO. They would become simple if microC ISR declarations were explained -that would avoid mistakes- . Remaining code can be ported (I agree) without trouble, using Arduino as a simple gcc -not g++, no Arduino specific functions (except delay_ms) - software :

As OP already knows how to paste his/her code into avr-freaks forum, it seems even simpler to paste it into an Arduino IDE window and to try to compile it: it will likely (as it is) complain because avr-libc include files are missing, and help for that topic, if needed, is trivial.... (and I hinted Arduino should be configured as to display the compiling invocations and errors + avrdude invocation : one can know where error occurs, and which one)

 

Anyway, some comments (which part of the port is soldered to traffic light , horns, push buttons : that might be very useful if one - a teacher, someone who tries to help-  wants to change microcontroller, say, or just to understand) should be added....

 

Oh, BTW : may be cards are bought by its college (and are they rich enough/competent enough : makes two distinct prerequisites - to buy the best ones?)

 

 

 

Last Edited: Tue. Oct 17, 2017 - 10:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
As far as I could understand : OP is studying electrical engineering -> computer science

Sometimes you are really hard to understand. What did you want to express with that arrow (->)?  Are you saying that computer science is a part of electrical engineering?

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Well I am very surprised the character "|" cannot be translated as "or"....

I meant computer science (parts of maths).or. (do you prefer Fortran 66/77 notation?) microinformatics (applied part of computer science)is a small part of electric engineering  (it is not, nowadays, an essential part...).

 

If it had been an essential part, maybe I would have been fierce (being stopped by details is annoying for a student; if it is an essential part of his work, helping him/her might be seen as cheating; if it is not, I do not hesitate trying to help and the first thing he/she should do might be to add commentaries : if one is not an expert, how can one understand a program one wrote? how can one understan and debug a program one did not write?)

Last Edited: Tue. Oct 17, 2017 - 12:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm afraid I have to agree with Johan - you can be very hard to understand.

 

He wasn't querying the use of "|" but the use of "->"

 

But, no, I don't think the use of "|" for "or" in plain prose makes any sense - for goodness' sake, you're only saving one single character!

 

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

Well , I suppose "therefore" has more characters than "->", does not it?

Oh, btw: are :

I think the easiest thing would probably be to start again from scratch.

and

t looks pretty straightforward to me - just the change of syntax for the ISRs.

 

and

ATMega 324PB, 168, 168PB, 328P, and 328PB are all available on XPlained (Pro or Mini) boards:

 

logically consistent? 

Are they consistent with the topic? (même si je ne suis pas ben bon en omericoin, j'savons lire un titre...)

And do every student, in any country, have a comfortable access to google, comfortable enough to avoid errors (if one has bugs, one posts it for the lazy web to fix it -> google just picks up bugs)  , thus giving some sense to lmtgfy-ing??

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

dbrion0606 wrote:
Well , I suppose "therefore" has more characters than "->", does not it?

It does;  but it conveys the meaning - which "->" does not.

 

 

dbrion0606 wrote:
Oh, btw: are :

I think the easiest thing would probably be to start again from scratch.

and

t looks pretty straightforward to me - just the change of syntax for the ISRs.

 

and

ATMega 324PB, 168, 168PB, 328P, and 328PB are all available on XPlained (Pro or Mini) boards:

 

logically consistent? 

They are alternatives.

 

The "start again from scratch" was if OP still wanted to use Arduino - since the code structure does not seem to be easily portable into that framework.

 

The XPlained option is if the OP wants minimum code change.

 

Are they consistent with the topic?

The root problem of the topic is that he has non-Arduino code and doesn't know how to get it into Arduino hardware.

That suggests one of two options:

 

  1. Convert the code to be Arduino compatible;
  2. Keep (almost) the same code, and use hardware that's easy to load.

 

 

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

They are alternatives.

Are these alternatives compatible with OP's status (having his/her school buying a better card?, accessing to google lists of bugs -ltmgfy -ing can lead to a list of unfinished projects, in the best case: it does not seem a  good alternative..., even if it were an excellent in a perfect world with perfect colleges, and infinite time|brains  to learn how to use a-studio simulator.)

 

BTW, an Arduino card is easy to upload using the IDE (and it is not that difficult to program it in plain gcc  : remain 5 lines out of >= 100 as you wrote); maybe it is what OP has been asked by his/her school??? (else, why has (s)he an expensive Arduino? to buy another, better, card).; plain gcc can be compiled by Arduino (suffit d'ajouter les bons fichiers inclus, je ne  ltmgfy -e pas google traduction quand je jaspinions en  argot gaullois).

 

Oh, I forgot "alternative", in omericon , does not convey any sense ("alternative facts/truths" seem oxymorons but make people laugh again).

Edited : pour info, je m'interdis, pour une question de décence (notion intraduisible en omericoin), de ltmgfiy -er... et de copier coller des phrases sorties de leur contexte .

 

Last Edited: Tue. Oct 17, 2017 - 03:12 PM