Advertisement
celem

R06A Arduino Test Code

Jul 8th, 2012
6,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.96 KB | None | 0 0
  1. /*
  2. ** Test of R06A RF decoder e/w SC2272-T4
  3. **
  4. ** This example uses a SainSmart I2C LCD2004 adapter for HD44780 LCD screens
  5. **
  6. ** LCD2004 Address pins 0,1 & 2 are all permenantly tied high so the address
  7. ** is fixed at 0x27
  8. **
  9. ** Written for and tested with Arduino 1.0
  10. ** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
  11. ** https://bitbucket.org/fmalpartida/new-liquidcrystal
  12. **
  13. ** Edward Comer
  14. ** LICENSE: GNU General Public License, version 3 (GPL-3.0)
  15. **
  16. ** NOTE: Tested on Arduino NANO whose I2C pins are A4==SDA, A5==SCL
  17. **       INT0 is on D2
  18. ** Wiring for Nano: A4->SDA, A5->SCL
  19. */
  20. #include <Wire.h>
  21. #include <LCD.h>
  22. #include <LiquidCrystal_I2C.h>
  23.  
  24. // These pins are on the PCF8574 I/O expander for I2C-bus, not the nano
  25. #define I2C_ADDR    0x27  // Define I2C Address where the PCF8574A is
  26. #define BACKLIGHT_PIN     3
  27. #define En_pin  2
  28. #define Rw_pin  1
  29. #define Rs_pin  0
  30. #define D4_pin  4
  31. #define D5_pin  5
  32. #define D6_pin  6
  33. #define D7_pin  7
  34.  
  35. #define  LED_OFF  0
  36. #define  LED_ON  1
  37.  
  38. #define PIN_D2_INT  0
  39.  
  40. // R06A defines - wired to Digital Arduino pins
  41. // Wire the R06A per this assignment
  42. #define R06A_VT 2    // used for INT0
  43. #define R06A_D0 3
  44. #define R06A_D1 4
  45. #define R06A_D2 5
  46. #define R06A_D3 6
  47.  
  48. int r06a_0, r06a_1, r06a_2, r06a_3 = 0; // storage for data states
  49. int dirty = 0;                          // interrupt has occurred flag
  50.  
  51. LiquidCrystal_I2C   lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
  52.  
  53. // Interrupt Service Routine attached to INT0 vector
  54. void pinD2ISR()
  55. {
  56.     // Provide a visual clue of the interrupt
  57.     digitalWrite(13, !digitalRead(13));  // Toggle LED on pin 13
  58.     // Grab the data states
  59.     r06a_0 = digitalRead(R06A_D0);      // Grab data for later consumption in loop()
  60.     r06a_1 = digitalRead(R06A_D1);
  61.     r06a_2 = digitalRead(R06A_D2);
  62.     r06a_3 = digitalRead(R06A_D3);
  63.     dirty = 1;              // flag interrupt occurance
  64. }
  65.  
  66. void setup()
  67. {
  68.   lcd.begin (20,4);
  69.  
  70. // Switch on the backlight
  71.   lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  72.   lcd.setBacklight(LED_ON);
  73.  
  74.   lcd.home ();                      // Home
  75.   lcd.print("Test of R06A Decoder");    // Logo 1st line
  76.   lcd.setCursor ( 0, 2 );           // Go to the 3rd line
  77.   lcd.print("DAT3 DAT2 DAT1 DAT0");
  78.  
  79.   attachInterrupt(PIN_D2_INT, pinD2ISR, RISING);    // Set D2 interrupt
  80.  
  81.   // setup the R06A decoder connections
  82.   pinMode(R06A_D0, INPUT);
  83.   pinMode(R06A_D1, INPUT);
  84.   pinMode(R06A_D2, INPUT);
  85.   pinMode(R06A_D3, INPUT);
  86. }
  87.  
  88. void loop()
  89. {
  90.     if(dirty)
  91.     {
  92.         dirty = 0;      // clear interrupt occurance flag
  93.         lcd.setCursor (15,3);     // go to LCD col 15 of line 4
  94.         lcd.print(r06a_0 ? "HIGH": "LOW ");
  95.         lcd.setCursor (10,3);     // go to LCD col 10 of line 4
  96.         lcd.print(r06a_1 ? "HIGH": "LOW ");
  97.         lcd.setCursor (5,3);      // go to LCD col 5 of line 4
  98.         lcd.print(r06a_2 ? "HIGH": "LOW ");
  99.         lcd.setCursor (0,3);      // go to LCD col 0 of line 4
  100.         lcd.print(r06a_3 ? "HIGH": "LOW ");
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement