element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
NexGen Flight Simuator Nexgen: CANaerospace: RSS: C-3436A Radio: Build iv: Code Review
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: phoenixcomm
  • Date Created: 16 Sep 2021 4:46 PM Date Created
  • Views 521 views
  • Likes 1 like
  • Comments 0 comments
  • offtheshelfch
  • flight simulator
  • nexgen
  • arduino mega 2560
  • c programing
  • rss
  • c-3436a radio set
  • bare metal system
Related
Recommended

Nexgen: CANaerospace: RSS: C-3436A Radio: Build iv: Code Review

phoenixcomm
phoenixcomm
16 Sep 2021

imageI have been fighting with the Arduino for the last few years. this time I wanted to simplify my code base by using a struct in my header file:

// typdef struct frequency {

  int bits[20][5] = {{1,1,0,0,1},{1,1,0,0,0},{1,1,1,0,0},{1,0,0,0,1},{1,1,1,1,0},

                  {0,0,0,1,0},{0,1,1,1,1},{0,0,1,0,0},{1,0,1,1,1},{0,1,0,0,0},

                  {0,0,0,1,1},{1,0,0,0,0},{1,0,1,0,1},{0,0,0,0,1},{0,0,1,1,0},

                  {0,1,0,1,1},{0,0,1,0,1},{0,0,1,1,0},{1,0,0,1,0},{0,1,1,0,0}};

 

  char channels[20][3]= {{000},{108},{109},{110},{111},{112},{113},{114},{115},{116},{117},

                        {118},{119},{120},{121},{122},{123},{124},{125},{126}};

      

// } channels;

#include "C3436.h"

int Status;

int F[5]={};

 

 

void setup() {

  // put your setup code here, to run once:

  // Start serial port

  Serial.begin( 9600 );

 

  // Khz Pins

  for (int i = 1; i < 6; i++){

      pinMode (pins[i], INPUT_PULLUP);}

  // Mhz Pins

  for (int ii = 6; ii < 11; ii++){

      pinMode (pins[ii], INPUT_PULLUP);}

  // Other stuff

      pinMode ( powerpin, INPUT_PULLUP );

      pinMode ( lightPower, OUTPUT);

}

This has been a disaster, in a function I tried in vain to access the channels.bits[][] member but to no avail.  In my function I can access bits[][] but not as a member of the struct.

My code is posted below:  I have been having cold stupid sweats about stupid scoping rules which don't make any sense to me as a C programmer. Even the silliness of the loop() is a little nutty. Once in it how the hell do you get out of it. Also when you call an ISR it is a void so you have to use a side effect (a bad thing), ISRs normally return something. I am going to use bare metal C programming. Here is a nice article on how to do it, he likes the silly platformIO, which is based on Mico$oft's Visual Studio, which is something that I want no part of. Me, I'm going to stick with my Swiss Knife, Eclipse IDE, it is clean and uncluttered. I will be using GCC for the AVR.  

image

 

void loop()

void loop() {

 

 

int Stat = start();

    if( Stat == 1 ) run();

}

int start()

int start( ) {

   // check pwrpin

   int pwrpin= digitalRead(powerpin);

   pwrpin = 1; // force power on

   switch ( pwrpin ) {

      case 0: {

        pwrpin = 0;

        break;}

      case 1: {

        pwrpin = 1;

        break;}

      default: {

        pwrpin = -1;

        break;}

      }

  return pwrpin; }

void run ()

void run () {

 

  int x;

  int temp[10];

 

  // read the freq pins

  for ( x = 0; x < 10; x ++) {

    temp[x] = digitalRead( pins[x]); }

 

  // Now test the KHz pins; test columns using double loops

  for (int y = 0; y < 10; y++){

     for (int x = 0; x < 5; x++ ){

      if ( temp[x] == lowFrequency[x][y] ) {

        continue; }

      else { break; }

      }}

 

   // Now  test the Mhz pins

   for (int y = 0; y < 20; y++){

     for (int x = 0; x < 5; x++ ){

//   if ( temp[x] == channels.bits[x][y] ) {

      if ( temp[x] == bits[x][y] ) {

        continue; }

      else { break; }

      }}

 

 

}

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube