Skip to content

Instantly share code, notes, and snippets.

View ksvbka's full-sized avatar
💭
CFF - Code for food 👍

Trung Kien ksvbka

💭
CFF - Code for food 👍
View GitHub Profile
@ksvbka
ksvbka / i2c_sw.c
Last active April 14, 2022 09:43
I2C Bit-Bangging - MSP430
/********************************************************************************
Module : I2C_SW
Author : 05/04/2015, by KienLTb - https://kienltb.wordpress.com/
Description : I2C software using bit-banging.
********************************************************************************/
/*-----------------------------------------------------------------------------*/
/* Header inclusions */
@ksvbka
ksvbka / printf.h
Last active August 29, 2015 14:18
Printf for UART MSP430
#include "msp430g2231.h"
#include "stdarg.h"
void putc(unsigned);
void puts(char *);
static const unsigned long dv[] = {
// 4294967296 // 32 bit unsigned max
1000000000, // +0
100000000, // +1
@ksvbka
ksvbka / i2c_hw.c
Last active September 8, 2024 14:12
I2C Hardware for MSP430
/********************************************************************************
Product: I2C - Hardware - Block
Module: I2C
Created: 12/04/2015, by KIENLTB
Description: I2C Driver for MSP430
********************************************************************************/
/*-----------------------------------------------------------------------------*/
@ksvbka
ksvbka / BitAlgorithm.c
Created April 15, 2015 01:15
Bit algorithm
//count the 1 bits in a int
int count_ones(unsigned int x)
{
int result = 0;
while (x != 0)
result++, x = x & (x-1);
return result;
}
@ksvbka
ksvbka / myMath.h
Last active August 29, 2015 14:19
My math
/*
Macro to convert the MSB/LSB of a 16-bit value to a 8-bit value
*/
#define GET_16BIT_MSB( x ) ( (uint8_t)( ( ( (uint16_t)(x) ) >> 8 ) & 0xFF ) )
#define GET_16BIT_LSB( x ) ( (uint8_t)( ( (uint16_t)(x) ) & 0xFF ) )
/* macro to write the 16-bit value into an 8-bit buffer */
#define BUF_SET_16BIT( buf, value ) \
do { \
((uint8_t *)(buf))[ 0 ] = GET_16BIT_MSB(value); \
@ksvbka
ksvbka / mpu6050.c
Last active June 19, 2022 01:46
Driver MPU6050 for MSP430
/********************************************************************************
Product: MPU6050
Module:
Created: 4/6/2015, by KienLTb
Description: Driver MPU6050 for MSP430
********************************************************************************/
/*-----------------------------------------------------------------------------*/
@ksvbka
ksvbka / delay.h
Created May 10, 2015 09:36
Define marco for delay
#ifndef DELAY_H
#define DELAY_H
#include msp430g2553.h
#ifndef F_CPU
#warning F_CPU not defined for <delay.h>. Using default
#define F_CPU 1000000UL // 1 MHz
#endif
@ksvbka
ksvbka / button.c
Last active April 11, 2021 10:10
Detect and process event of button (click, double click, hold). Use for MSP430.
/********************************************************************************
Product: MSP430 FrameWork
Module: Button
Created: 5/18/2015, by KIENLTB
Description: Button framework
********************************************************************************/
/*-----------------------------------------------------------------------------*/
@ksvbka
ksvbka / datapackProc.c
Last active August 29, 2015 14:21
Lib to process data package
/********************************************************************************
Product: MSP430 Service Framework
Module: DataPackage Service
Created: 5/23/2015, by KIENLTB
Description: Service for process DataPackage
********************************************************************************/
/*-----------------------------------------------------------------------------*/
@ksvbka
ksvbka / Makefile
Created May 29, 2015 18:03
A simple char driver for training :D
obj-m := charDev.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions *.symvers *.order