HX711
HX711
HX711
#include <16f877.h>
#fuses XT, NOWDT, NOPROTECT, NOLVP, PUT, BROWNOUT
#use delay(clock = 4000000) // Fosc = 4MHz
#define use_portb_lcd TRUE // Puerto B para el manejo de la LCD
#include <lcd420.c> // Libreria de manejo de la LCD
#BIT ADDO = 0X08.0 // 0x08 = Puerto D, posicion en el banco de memoria
#BIT ADSK = 0X08.1
#include <main.h>
#include <stdio.h>
#ZERO_RAM
#define HX711_DO PIN_B15
#define HX711_CLK PIN_B14
int32 measurement(void);
void main()
{
int1 test=0;
unsigned int32 Count,BUFFER[30],offseeet=0,mied=0;
unsigned int8 i=0;
while(TRUE){
while(i<10){
Count=measurement();
BUFFER[i]=Count;
mied+=BUFFER[i];
i++;
}
i=0;
mied/=11;
if(test==0){
offseeet=mied;
test=1;
}
//Count=measurement();
mied-=offseeet;
//printf("data=%lu \n\r",Count);
printf("mied=%lu \n\r",mied);
//delay_ms(1);
//printf("\f");
}
}
//********************************************
int32 measurement(void){
unsigned int32 Count;
unsigned int8 i,A_1,A_2,A_3;
/*http://www.ebay.com/itm/New-Weighing-Sensor-AD-Module-Dual-channel-24-bit-A-D-
Conversion-HX711-Shieding-/400567204760?pt=LH_DefaultDomain_0&hash=item5d43aa7b9
8
http://www.ebay.com/itm/Electronic-Scale-Sensor-HX711-ADC-Bridge-Weighing-Anti-J
amming-For-Arduino-AVR-/171217937819?pt=LH_DefaultDomain_0&hash=item27dd62659b
*/
//-----------------------------------------------------------------------------
// Title: i2c_Flex_LCD
// Description: Driver for common LCD with 1/2/3 or 4 row modules using PCF857
4T interface board with I2C protocol.
// Date: Nov-2013
// Ver.Rev.: 1.0
// Author: Hugo Silva (sergio-hugo@bol.com.br) #Based on the routines of
20X4_LCD_I2C_DRIVER.h from Pumrin S.
//-----------------------------------------------------------------------------
//
// lcd_init() Must be called before any other function.
//
// lcd_putc(c) Will display c on the next position of the LCD.
//
// \f Clear LCD dispay
// \1 Set write position on LCD Line 1
// \2 Set write position on LCD Line 2
// \3 Set write position on LCD Line 3
// \4 Set write position on LCD Line 4
//
// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)
//
//-----------------------------------------------------------------------------
// LCD pins D0-D3 are not used.
//-----------------------------------------------------------------------------
//
// Commment : Control of a compatible LCD HITACHI from a bus I2C with
// an EXPANDER of I/O with connection I2C. The tests of these
// routines have been programmed using the IC PCF8574T of Phillips.
// I used 4 bits mode programming. The 8 bits mode programming
// is possible if you use 2 x PCF8574T.
//
// As defined in the following structure the pin connection is as follows:
//
// PCF8574P LCD
// ======== ======
// P0 RS
// P1 RW
// P2 Enable
// P3 Led Backlight
// P4 D4
// P5 D5
// P6 D6
// P7 D7
//
// The SCL and SDA pins should be pull-up resistor as shown below:
//
// +5v
// |
// <
// > 4.7K
// <
//To PIC | To i2c slave
//pin xx ------------------ SDA pin
//(SDA)
// +5v
// |
// <
// > 4.7K
// <
//To PIC | To i2c slave
//pin xx ------------------ SCL pin
//(SCL)
//
//To PIC To i2c slave
//Vss pin ----------------- Vss or ground pin
// |
// -----
// --- Ground
// -
//
// THIS DOCUMENT IS PROVIDED TO THE USER "AS IS"
//-----------------------------------------------------------------------------
#define LCD_ADDR 0x7E //I2C slave address for LCD module for PCF8574A
#define ON 1
#define OFF 0
#define RS 0b00000001 //P0 - PCF8574T Pin connected to RS
#define RW 0b00000010 //P1 - PCF8574T Pin connected to RW
#define EN 0b00000100 //P2 - PCF8574T Pin connected to EN
#define BACKLIGHT_LED 0b00001000 //P3 - PCF8574T Pin connected to BACKLIGHT LE
D
#define lcd_line_one 0x80 // LCD RAM address for line 1
#define lcd_line_two 0xC0 // LCD RAM address for line 2
#define lcd_line_three 0x94 // LCD RAM address for line 3
#define lcd_line_four 0xD4 // LCD RAM address for line 4
byte address;
int1 lcd_backlight=ON;
void i2c_send_nibble(unsigned char data)
{
i2c_start();
delay_us(20);
i2c_write(LCD_ADDR); //the slave addresse
delay_us(20);
i2c_write(data);
delay_us(20);
i2c_stop();
delay_us(20);
}
void lcd_send_byte(unsigned char data)
{
if (lcd_backlight) data=data|EN|BACKLIGHT_LED; else data=data|EN; //set
pin EN
i2c_send_nibble(data);
data=data-4; //toggle EN back to 0
i2c_send_nibble(data);
}
void lcd_clear()
{
lcd_send_byte(0x00);
lcd_send_byte(0x10);
delay_ms(2);
}
void lcd_init()
{
delay_ms(200); //LCD power up delay
//Request works on the command by set the RS = 0 R/W = 0 write
lcd_send_byte(0x00);
lcd_send_byte(0x10);
lcd_send_byte(0x00);
lcd_send_byte(0x00);
lcd_send_byte(0x10);
//First state in 8 bit mode
lcd_send_byte(0x30);
lcd_send_byte(0x30);
//Then set to 4-bit mode
lcd_send_byte(0x30);
lcd_send_byte(0x20);
//mode 4 bits, 2 lines, characters 5 x 7 (28 h)
lcd_send_byte(0x20);
lcd_send_byte(0x80);
//no need cursor on (0Ch)
lcd_send_byte(0x00);
lcd_send_byte(0xC0);
//the cursor moves to the left (06 h)
lcd_send_byte(0x00);
lcd_send_byte(0x60);
//clears the display
lcd_clear();
}
void lcd_gotoxy( byte x, byte y)
{
static char data;
switch(y)
{
case 1: address= lcd_line_one; break;
case 2: address= lcd_line_two; break;
case 3: address= lcd_line_three; break;
case 4: address= lcd_line_four; break;
default: address= lcd_line_one; break;
}
address+=x-1;
data=address&0xF0;
lcd_send_byte(data);
data=address&0x0F;
data=data<<4;
lcd_send_byte(data);
}
//Display the character on LCD screen.
void LCD_PUTC(char in_data)
{
char data;
switch(in_data)
{
case '\f': lcd_clear() ; break;
case '\1': lcd_gotoxy(1,1); break;
case '\2': lcd_gotoxy(1,2); break;
case '\3': lcd_gotoxy(1,3); break;
case '\4': lcd_gotoxy(1,4); break;
default:
data=in_data&0xF0;
data=data|RS; //set RS pin to 1
lcd_send_byte(data);
data=in_data&0x0F;
data=data<<4;
data=data|RS; //set RS pin to 1
lcd_send_byte(data);
break;
}
}
HX711_set_scale(1375);
HX711_set_gain(128);
HX711_tare(20);
for(;;)
{
loadvalue=HX711_get_units(10);// takes 10 measurement and average
lcd_gotoxy(1,1);
printf(lcd_putc,"Value");
lcd_gotoxy(1,2);
printf(lcd_putc," ");
lcd_gotoxy(1,2);
printf(lcd_putc,"%4.1f gr",loadvalue);
delay_ms(200);
/*
HX711_power_down();
delay_ms(1000);
HX711_power_up();
*/
}