3003 views|5 replies

3836

Posts

19

Resources
The OP
 

I want a program related to the msp430f5529 light or rain sensor. [Copy link]

/*********************************************************** File name: iic.c Author: czhang Description: Subroutine of iic bus. Version: 1.0, October 11, 2003 **********************************************************************************************/ #include  
#include "BH1750.h" #include "iic.h" #include "general.h" /**************************************************************************** Initialize IIC ***************************************************************************/ void InitIIC() { IIC_DIR |= IIC_SCL; //SCL pin is output IIC_DIR &= ~IIC_SDA; //SDA pin is input C_SCL; Stop(); } /******************************************************************************* There is a short delay because the speed of MSP430 is relatively fast. The user can adjust the delay length according to the clock frequency********************************************************************/ void delay() { unsigned char q0; for(q0=0;q0<20;q0++) { _NOP(); } } /******************************************************************************* Start IIC bus***************************************************************************/ void Start() { SDA_OUT; S_SDA; delay(); S_SCL; delay(); C_SDA; delay(); C_SCL; delay(); } /******************************************************************************* Stop operation, release IIC bus***********************************************************************/ void Stop() { SDA_OUT; C_SCL; delay(); C_SDA; delay(); S_SCL; delay(); S_SDA; delay(); } /*************************************************************************** IIC bus response***********************************************************************/ void Ack() { SDA_OUT; C_SDA; delay(); S_SCL; delay(); C_SCL; delay(); S_SDA; } /******************************************************************************* IIC bus no response***************************************************************************/ void NoAck() { SDA_OUT; S_SDA; delay(); S_SCL; delay(); C_SCL; delay(); } /******************************************************************************* IIC bus test response return value: IIC response bit value 0: response 1: no response ******************************************************************************/ unsigned char TestAck() { unsigned char ack; S_SCL; delay(); SDA_IN; delay(); ack=READ_SDA; delay(); C_SCL; delay(); return(ack); } /*********************************************************************** IIC bus write 8-bit data input: 8-bit data to be written***********************************************************************/ void Write8Bit(unsigned int input) { unsigned char temp,q0; SDA_OUT; for(temp=8;temp!=0;temp--) { q0=input&0x80; if(q0==0x80) S_SDA; else C_SDA; delay(); S_SCL; delay(); C_SCL; delay(); input=input<<1; } } /******************************************************************************* IIC bus reads 8-bit data Return value: read 8-bit data **********************************************************************/ unsigned char Read8Bit() { unsigned char temp,q0,rbyte=0; SDA_IN; for(temp=8;temp!=0;temp--) { S_SCL; delay(); rbyte=rbyte<<1; SDA_IN; q0=READ_SDA; if(q0==IIC_SDA) rbyte=rbyte|0x1; delay(); C_SCL; delay(); } return(rbyte); } Have you used it before, feel it~?

This post is from Microcontroller MCU

Latest reply

Is there something wrong with the program? Or do I not know how to use the light and rain sensors?  Details Published on 2018-12-7 18:37
 

9703

Posts

24

Resources
2
 
Isn't the light sensor just an ADC? Does it sample? Use a voltage divider resistor externally. If the rainwater is a capacitor type, you can look for a Zhangchi oscillation circuit made by TI using an MSP430 comparator to measure capacitance.
This post is from Microcontroller MCU
 
Personal signature虾扯蛋,蛋扯虾,虾扯蛋扯虾
 

2618

Posts

0

Resources
3
 
What littleshrimp said is quite right, just do it as he said.
This post is from Microcontroller MCU
 
 
 

102

Posts

0

Resources
4
 
Just write it yourself.
This post is from Microcontroller MCU
 
 
 

6570

Posts

0

Resources
5
 
There seems to be a problem with the IIC bus reading program
This post is from Microcontroller MCU
 
 
 

6366

Posts

4936

Resources
6
 
Is there something wrong with the program? Or do I not know how to use the light and rain sensors?
This post is from Microcontroller MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list