Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Arduino Code Problem

Status
Not open for further replies.

Mike - K8LH

Well-Known Member
Hi guys. I'm trying to copy a bit in a local variable to another bit position within that variable but so far "no joy". Basically I'm trying to copy bit 6 in the "hi" variable to bit 7 but none of the instructions I've tried are recognized by the compiler (the size of the compiled program doesn't change and there are no error messages). Please help?

TIA... Cheerful regards, Mike

Code:
  /******************************************************************
   *  Flash_v1    (28C256 EEPROM Programmer)                        *
   *                                                                *
   *  Mike McLaren, K8LH                                            *
   *  Micro Application Consultants                                 *
   *                                                                *
   *  02-Dec-2020    Arduino 1.8.13 / Arduino Uno                   *
   ******************************************************************/


   #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~(1<<bit))  // clear bit
   #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= 1<<bit)     // set bit

  /******************************************************************
   *  variables & constants                                         *
   ******************************************************************/

   #define A15    PORTB1
   #define CE     PORTB2
   #define OE     PORTB3
   #define WE     PORTB4

   uint32_t address = 0x0100;
   const char hex[] = "0123456789abcdef";

  /******************************************************************
   *                                                                *
   ******************************************************************/

   void setAddr(uint32_t addr)  // hard coded for 28C256
   { byte hi = (addr >> 8) & 0x7F;  // A14..A8 bits
     byte lo = addr & 0xFF;
  /*
   *  set data bus lines to outputs
   */
     DDRB |= 0x03;              // PB1..PB0 (D7..D6) Outputs    ( 6)
     DDRD |= 0xFC;              // PD7..PD2 (D5..D0) Outputs    ( 6)
  /*
   *  strobe latches with address hi (A15..A8)
   */
     if(hi >= 64) { hi |= 0x80; }                <------------------------------
     PORTB = (PORTB & 0xFC) | (hi >> 6);
     PORTD = (PORTD & 0x03) | (hi << 2);
     cbi(PORTB, OE);            // OE(PB3) = 0                  ( 2)
     sbi(PORTB, OE);            // OE(PB3) = 1                  ( 2)
  /*
   *  strobe latches with address lo (A7..A0)
   */
     PORTB = (PORTB & 0xFC) | (lo >> 6);
     PORTD = (PORTD & 0x03) | (lo << 2);
     cbi(PORTB, OE);            // OE(PB3) = 0
     sbi(PORTB, OE);            // OE(PB3) = 1

     DDRB &= 0xFC;              // PB1..PB0 (D7..D6) Inputs
     DDRD &= 0x03;              // PD7..PD2 (D5..D0) Inputs
   }

  /******************************************************************
   *                                                                *
   ******************************************************************/



  /******************************************************************
   *  main                                                          *
   ******************************************************************/

   void setup()
   {
     sbi(PORTB, CE);            // CE(PB2) = 1
     sbi(PORTB, OE);            // OE(PB3) = 1
     sbi(PORTB, WE);            // WE(PB4) = 1
     DDRB |= 0x3C;              // CE/OE/WE/A16 Outputs
     DDRC |= 0x30;              // PC5(A18)..PC4(A17) Outputs

     Serial.begin(115200);      //
     Serial.print(F("EEPROM Test "));
     Serial.println();          //
   }

   void loop()
   {
     if(Serial.available())      //
     { Serial.write(Serial.read());
       setAddr(0x0100);
     }                           //
   }                             //
Flash Programmer #2.pngFlash Programmer Pic.png
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top