CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Output of binary pulses of up / down counting by I2C

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
emazzu630



Joined: 14 Aug 2018
Posts: 20
Location: Ouro Verde - SC

View user's profile Send private message

Output of binary pulses of up / down counting by I2C
PostPosted: Tue Aug 14, 2018 4:59 pm     Reply with quote

Binary pulse output from the up / down counting shown on the 7-segment display via I2C pins.

Hi, I'm new here and for some time I'm trying to work out an up / down counter pulse output. The output must be by I2C and with each change of the count, the binary pulses of the numbers shown in the display must be transmitted.
Example: I stopped the count at "1250", then the last pulse train on the I2C bus was "10011100010", if the display number is showing "8955" then the binary pulses were "10001011111011" and so on. I have the counter with 7-segment display, and I need to mount that part of the I2C code that outputs the count in binary.
If anyone knows how to get this output divided by 5, then I can save on an external integrated circuit that does this division. The project is compiled by CCS C Compiler.

Once this post is answered, I will send the source code.


Last edited by emazzu630 on Tue Aug 28, 2018 10:49 pm; edited 2 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Output of binary pulses of up / down counting by I2C
PostPosted: Wed Aug 15, 2018 5:59 pm     Reply with quote

emazzu630 wrote:

I need to mount that part of the I2C code that outputs the count in binary.

What i2c device will receive the i2c binary pulses ?

Here is a sample program to send 16 bits by i2c. I have divided the
count by 5 before sending it, because you said you wanted that done.
This program will probably not be correct for your application, because
you have not told us what device will receive the i2c data.
Code:
#include <16F1847.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4M)

#use i2c(Master, I2C1, slow)

#define I2C_SLAVE_WRITE_ADDRESS 0xC0

void send_i2c_word(int8 i2c_slave_address,  int16 value)
{
i2c_start();
i2c_write(i2c_slave_address);
i2c_write(value);  // Send LSB first
i2c_write(value >> 8);   // Send MSB
i2c_stop();
}

//====================
void main(void)
{
int16 count;

count = 1250;
send_i2c_word(I2C_SLAVE_WRITE_ADDRESS, count/5);

delay_ms(10);

count = 8955;
send_i2c_word(I2C_SLAVE_WRITE_ADDRESS, count/5);

while(TRUE);
}

---------------------------------
Edited to correct a typo.


Last edited by PCM programmer on Fri Aug 17, 2018 4:24 pm; edited 1 time in total
emazzu630



Joined: 14 Aug 2018
Posts: 20
Location: Ouro Verde - SC

View user's profile Send private message

Saída de pulsos binários de contagem up/down por I2C
PostPosted: Thu Aug 16, 2018 8:03 am     Reply with quote

Thank you "PCM Programmer",
I'm waiting for the correct code, below the description of what the
program should do.

I am using PIC16F877A in the main function. He must send
display information in binary to another PIC16F877A (slave).
Binary data should be output in parallel via PORTB and PORTD

The binary code at the I2C output shall be proportional to the
display is showing. I added 2 increment / decrement buttons
to count from "5 out of 5". And 2 buttons increment / decrement
to count from "1000 out of 1000".
The output pulses divided by "5" must be proportional, or
ie if the number shown is "2590" then the binary code
fired will be "1000000110" (518). If another number shown is
"8785", then the binary code fired will be "11011011101" (1757).
Each time the count stops, the number that appears
display, in torque on the I2C bus.

From "0000" to "9999", the binary code must be generated every
change in display numbers counting from "5 out of 5", or from
"1000 in 1000", but by dividing by "5", the output will be
"1 in 1" or "200 in 200".

I urgently need this code in binary conversion CCS
and the output by bus I2C. And then the parallel output on the slave PIC16F877A.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group