User Tools

Site Tools


dev8051:code8051

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dev8051:code8051 [2024/11/11 11:50] – created azmandev8051:code8051 [2024/11/12 10:29] (current) – [Code: relay] azman
Line 6: Line 6:
  
 ++++ Testing IR module and HC-SR04 ultrasonic sensor module. | ++++ Testing IR module and HC-SR04 ultrasonic sensor module. |
-<file c test0.c>+<file c nmk322_test0.c>
 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
 #include "uart.h" #include "uart.h"
Line 229: Line 229:
  
 ++++ Testing Base Kit (202425s1). | ++++ Testing Base Kit (202425s1). |
-<file c basetest.c>+<file c nmk322_basetest.c>
 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
 /* override default tick values */ /* override default tick values */
Line 256: Line 256:
  P1 = seg7[loop] ^ mask;  P1 = seg7[loop] ^ mask;
  timer_tick00();  timer_tick00();
 + }
 + }
 +}
 +/*----------------------------------------------------------------------------*/
 +</file>
 +++++
 +
 +++++ Testing RFID (FRC522) and OLED (ssd1306). |
 +<file c nmk322_test2.c>
 +/*----------------------------------------------------------------------------*/
 +#include "uart_hexascii.h"
 +#include "oled_ssd1306.h"
 +#include "cstr_hexascii.h"
 +#include "frc522.h"
 +#define APPTITLE "NMK322 RFID/OLED"
 +/*----------------------------------------------------------------------------*/
 +void main(void) {
 + __xdata cstr_t buff; /* default: 64-bytes long */
 + unsigned char temp, stat, loop, size;
 + unsigned char pdat[FRC522_MAX_RXSIZE], reqa[2];
 + /** initialize */
 + cstr_init(&buff);
 + uart_init();
 + i2c_init();
 + oled1306_init();
 + spi_init();
 + atqa = reqa;
 + /* initialize mf contactless card reader */
 + /** say something... */
 + uart_puts("\n----------------\n");
 + uart_puts(APPTITLE);
 + uart_puts("\n----------------\n\n");
 + oled1306_puts(APPTITLE);
 + temp = frc522_init();
 + if (!temp||temp==0xff) {
 + uart_puts("** Cannot find FRC522 hardware! Aborting!\n");
 + hang();
 + }
 + uart_puts("FRC522 found. Firmware version is 0x");
 + uart_send_hexbyte(temp);
 + uart_puts(".\n");
 + /** main loop */
 + while (1) {
 + stat = frc522_scan(pdat,&size);
 + if (stat==FRC522_OK) {
 + uart_puts("## TAG(");
 + uart_send_hexbyte(stat);
 + uart_puts("|");
 + uart_send_hexbyte(reqa[0]);
 + uart_puts(",");
 + uart_send_hexbyte(reqa[1]);
 + uart_puts("):");
 + cstr_null(&buff);
 + for (loop=0;loop<size-1;loop++) { /** UID is size-1 bytes */
 + uart_send('[');
 + uart_send_hexbyte(pdat[loop]);
 + cstr_append_hexbyte(&buff,pdat[loop]);
 + uart_send(']');
 + }
 + uart_send('\n');
 + oled1306_set_cursor(2,0);
 + oled1306_puts("#TAG: ");
 + oled1306_puts(buff.buff);
 + loop_delay(3000);
 + oled1306_clear_row(2);
 + }
 + else if (stat!=FRC522_ERROR_NO_TAG&&stat!=FRC522_ERROR_REQ_A) {
 + uart_puts("** Scan Failed (0x");
 + uart_send_hexbyte(stat);
 + uart_puts("):");
 + for (loop=0;loop<FRC522_MAX_RXSIZE;loop++) {
 + uart_send('[');
 + uart_send_hexbyte(pdat[loop]);
 + uart_send(']');
 + }
 + uart_send('\n');
 + oled1306_set_cursor(3,0);
 + oled1306_puts("*TAG: ERROR!");
 + loop_delay(3000);
 + oled1306_clear_row(3);
  }  }
  }  }
Line 265: Line 345:
 ===== Code: relay ===== ===== Code: relay =====
  
-++++ Testing basic relay. |+Testing basic relay.
 <file c relay.c> <file c relay.c>
 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
Line 295: Line 375:
 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
 </file> </file>
-++++ 
  
 ===== Code: gtuc51 ===== ===== Code: gtuc51 =====
dev8051/code8051.1731297017.txt.gz · Last modified: by azman