Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Ryanhu1015
Ryanhu1015 / RF_recv.c
Last active March 1, 2019 14:01
embedded rookie
unsigned char tmpbuf[128];
void light_condition_receiver(void);
void RxPacket(void);
void main(void)
{
//hardware initialization...
if(P3_5)
{
@Ryanhu1015
Ryanhu1015 / RF.c
Last active February 2, 2019 09:20
embedded rookie
#include "globalvar.h" // button2_time_cnt is defined in the header file
#include "function.h"
#define P3_5 1 // if P3_5 is 1, it will be the transmitter
#define period 1000
unsigned char Packet_Tx[8]; // if initialize, this array will be a "constant", which can't be modified in code.
void WriteFIFO(void);
void WriteFIFO(void)
@Ryanhu1015
Ryanhu1015 / button_clicked.c
Last active February 1, 2019 17:47
embedded rookie
#define Button1_SW1 P3_2 // P3_2 is one of the input button pin
unsigned int button1_time_cnt; //global variable
void Timer0ISR (void) interrupt 1 // trigger per 1 ms
{
TF0 = 0; // Clear Timer0 interrupt
TH0 = (65536-t0hrel)>>8; // Reload Timer0 high byte,low byte
TL0 = 65536-t0hrel;
button1_time_cnt <<= 1 ;
@Ryanhu1015
Ryanhu1015 / adc_test_2.c
Last active October 20, 2018 15:12
embedded rookie
unsigned short ADCbuffer;
unsigned short wc_DelayTimeOutCounter;
//skip the functions prototypes
void main(){
//initiate hardware
//..
//..
while(1){
if(wc_DelayTimeOutCounter==100){ // grab the value per second
@Ryanhu1015
Ryanhu1015 / adc_test.c
Created October 20, 2018 13:41
embedded rookie
void ADC_Init(void);
void ADC_Init(){
P0M=0x38;// set I/O as input/output mode
P0CON |= 0x02;//let P01 as a pure analog pin
P0UR=0;// disable the pull-high
ADM=0x81;// enable ADC function, and use AIN1
ADR=0x60;// enable AIN channel, and set clock rate = fosc/1
@Ryanhu1015
Ryanhu1015 / uart_test_2.c
Last active October 22, 2020 16:35
embedded rookie
void txsenddata(short);
char ch;
char chstring[]="Please type something to test: ";
void main(){
for(int i=0; i<sizeof(chstring); i++) txsenddata(chstring[i]);
while(1){
if(enableWrite){
txsenddata(ch);
enableWrite=0;
@Ryanhu1015
Ryanhu1015 / uart_test.c
Last active September 23, 2018 05:54
embedded rookie
void UART_Init(void);
void txsenddata(short);
char rxreceivedata(void);
uint8_t enableWrite=0;
char ch;
char chstring[]="Please type something to test: ";
void main(){
//initial function setting..
for (int i=0; i<sizeof(chstring); i++) txsenddata(chstring[i]);
@Ryanhu1015
Ryanhu1015 / pwm.c
Last active August 27, 2018 14:47
embedded rookie
enum{off, on, pwm}
sbit pwmOut = P0^1;
const int pwmValue=96;//120*0.8, which means 80% dutycycle
void PWM_Init(void);
void PWM(uint8_t status);
void PWM_Init(){
T3YH=0x78;// 0-120 pieces
T3YL=0x00;
@Ryanhu1015
Ryanhu1015 / timer0.c
Created August 27, 2018 10:27
embedded rookie
#include <stdio.h>
#include <SN8F5701.H>
//variable
int count_millis=0;
uint8_t count_sec=0;
uint8_t count_min=0;
//prototype of functions
void Timer0_Init(void);
@Ryanhu1015
Ryanhu1015 / main.c
Created August 20, 2018 08:09
embedded rookie
#include <stdio.h>
#include <SN8F5701.H>
void Timer0_Init(void);
void main(){
//initial function write down here, like the one "setup" function in Arduino
Timer0_Init();
//
while(1){
//just like the "loop" function in Arduino