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

Tm1637 CCS C

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



Joined: 09 Aug 2020
Posts: 3
Location: turkey

View user's profile Send private message Visit poster's website

Tm1637 CCS C
PostPosted: Sun Aug 09, 2020 3:01 am     Reply with quote

Hello friends
I want to make a clock thermometer with TM1627, I couldn't drive.
I found a code written in c, I did not edit it
Could you help?

Code:

#include <tm1637_pic.h>

#include "DS1302.C"
#include "DHT11.C"
#include  "TM1637-BOLT.h"
#define bright MAX_BRIGHT

byte saniye,dakika,saat,gun,ay,yil,haftanin_gunu;
unsigned int  i=0;
char birler=0, onlar=0,yuzler=0,binler=0,sayi=0;
float sicaklik,nem;

long a=0;

unsigned char digits[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};

void main()
{
//port_a_pullups(0x0C);
rtc_init();
InitTM1637();

//displayValues(0,0,0,0);

output_high(pin_a3);
delay_ms(500);
output_low(pin_a3);

while(TRUE)
   {

    for(a=1;a<9999;a++)
      {
       displayValues(digits[(a/1000)%10], digits[(a/100)%10], digits[(a/10)%10], digits[a%10]);

       delay_ms(250);
      }


/*
    displayValues(0,0,0,0);
     
    displayValues(digits[(saat/10)%10], digits[saat%10] | 0x80, digits[(dakika/10)%10], digits[dakika%10]);
    delay_ms(500);   
    writeRawDigit(digits[saat%10],1);
     
 */   
   }

}



Code:

//TM1637.H
#define CLK pin_a0
#define DIO pin_a1


//#define CLK_HIGH  pin_a1
//#define DIO_HIGH TRISCbits.TRISC1 = 1

#define LOW_BRIGHT 0X00
#define MID_BRIGHT 0X02
#define MAX_BRIGHT 0X07

void InitTM1637(unsigned char BRIGHT);
void Delay_us(unsigned int useconds);
void start(void);
void ask(void);
void stop(void);
void writeByte(unsigned char oneByte);
void writeRawDigit(unsigned char segment, unsigned char nDigit);
void displayValues(unsigned char segment0, unsigned char segment1, unsigned char segment2, unsigned char segment3);

//
//   Inicializa y ajusta el brillo del display TM1637
//
void InitTM1637()
{
   start();
   writeByte(0x88 | 0X07);
   ask();
   stop();
}

//
//   Función de retardos ajustada a los requerimientos de la comunicación con el display TM1637
//
void Delay_us(unsigned int useconds)
{
   unsigned int i;
   for(i=0; i < useconds; i++)
   Delay_us(20);
}

//
//   Función que inicia la comunicación en el display TM1637
//
void start(void)
{
   output_high(clk);
   output_high(dio);
   Delay_us(2);
   output_low(dio);
}

//
//   Función que permite saber si el dato o comando enviado al display TM1637 ha sido recibido y
//   procesado correctamente
//
void ask(void)
{
   output_high(dio);
   output_low(clk);
   Delay_us(5);
   while(dio==0);
   output_high(dio);
   Delay_us(2);
   output_low(dio);
   output_low(clk);
}

//
//   Secuencia de paro, necesaria para el correcto funcionamiento del protocolo de comunicación
//   con el display TM1637
//
void stop(void)
{
   output_low(clk);
   Delay_us(2);
   output_low(dio);
   Delay_us(2);
   output_high(clk);
   Delay_us(2);
   output_high(dio);
}

//
//   Envia por el pin DIO los bits de un byte, envia serialmente los datos
//
void writeByte(unsigned char oneByte)
{
   unsigned char i;
   
   for(i=0; i<8; i++)
     {
      output_low(clk);
      if(oneByte & 0x01)
         output_high(dio);
      else
         output_low(dio);
      Delay_us(3);
      oneByte = oneByte >> 1;
      output_high(clk);
      Delay_us(3);
     }
}

//
//   Esta función envía al módulo TM1637 un byte con la representación en 7 segmentos en la
//   posción nDigit
//
void writeRawDigit(unsigned char segment, unsigned char nDigit)
{
   start();
   writeByte(0x44);
   ask();
   stop();
   start();
   writeByte(0xC0 | (nDigit & 0x07));
   ask();
   writeByte(segment);
   ask();
   stop();
}

//
//   Envía 4 caracteres al módulo TM1637 desde la posición 0 hasta la 4 de los segmentos
//
void displayValues(unsigned char segment0, unsigned char segment1, unsigned char segment2,
               unsigned char segment3)
{
   start();
   writeByte(0x40);
   ask();
   stop();
   start();
   writeByte(0xC0);
   ask();
   writeByte(segment0);
   ask();
   writeByte(segment1);
   ask();
   writeByte(segment2);
   ask();
   writeByte(segment3);
   ask();
   stop();
}






[url="https://ibb.co/SVhS0tZ"][/url]

[url="https://ibb.co/94z2Yqm"][/url]

[url="https://ibb.co/s3fQS29"][/url]
_________________
okumadığın gün karanlıktasın
temtronic



Joined: 01 Jul 2010
Posts: 9102
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Aug 09, 2020 4:37 am     Reply with quote

comments

1st line of every PIC program must be the processor type. I don't see that in your program. Something like..
#include <18f46k22.h>

2nd. can you get an LED to blink at 1Hz ? This is th efirst program you should write as it wll confirm you can compile/download code and the PIC hardware does function.

3rd. probably most important is this REAL hardware or a 'simulation' ?
Real hardware, we can help. If a 'proteus 'simulation', sorry I can't help. proteus is a very poor, defective simulator, well known to NOT be reliable or trustworthy.
yakup1890



Joined: 09 Aug 2020
Posts: 3
Location: turkey

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 09, 2020 7:04 am     Reply with quote

First of all, thank you for your comment.

1-#include <tm1637_pic.h>
available in

2-
I wrote in the program
Code:

output_high(pin_a3);
delay_ms(500);
output_low(pin_a3);

3-
I tried both in proteus and real



temtronic wrote:
comments

1st line of every PIC program must be the processor type. I don't see that in your program. Something like..
#include <18f46k22.h>

2nd. can you get an LED to blink at 1Hz ? This is th efirst program you should write as it wll confirm you can compile/download code and the PIC hardware does function.

3rd. probably most important is this REAL hardware or a 'simulation' ?
Real hardware, we can help. If a 'proteus 'simulation', sorry I can't help. proteus is a very poor, defective simulator, well known to NOT be reliable or trustworthy.

_________________
okumadığın gün karanlıktasın
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Sun Aug 09, 2020 9:20 am     Reply with quote

You don't show us what is in tm1637_pic.h

It needs it's very first line to have:
#include <18f46k22.h>

Then the fuses and the clock definitions. The code cannot work without
these.
yakup1890



Joined: 09 Aug 2020
Posts: 3
Location: turkey

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 09, 2020 1:34 pm     Reply with quote

Code:
#include <12F683.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES PUT                      //Power Up Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset

#use delay(internal=4MHz)
#use FIXED_IO( A_outputs=PIN_A5,PIN_A4,PIN_A2,PIN_A1,PIN_A0)

I did flash to test the code is working.
Code:

output_high(pin_a3);
delay_ms(500);
output_low(pin_a3);



Ttelmah wrote:
You don't show us what is in tm1637_pic.h

It needs it's very first line to have:
#include <18f46k22.h>

Then the fuses and the clock definitions. The code cannot work without
these.

_________________
okumadığın gün karanlıktasın
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