Autor Tópico: Contador regressivo  (Lida 5683 vezes)

Description:

0 Membros e 1 Visitante estão vendo este tópico.

Offline caipira

  • Novato
  • *
  • Posts: 9
  • Sexo: Masculino
  • GUIA-CNC
Contador regressivo
« Online: 26 de Janeiro de 2012, 16:32 »
Boa tarde.
Tenho em mente fazer um contador decrescente, do tipo quantos dias, horas e minutos (e se puder ser, segundos) que faltam para um determinado evento. Já fiz algumas pesquisas na net, mas não encontrei nada.
Alguém me pode ajudar?
Desde já os meus agradecimentos.
Carlos Lavrador

Offline Blackmore

  • CNCMASTER
  • ******
  • Posts: 1568
  • Sexo: Masculino
  • Profissão: Projetista Mecânico/Automação
Re:Contador regressivo
« Resposta #1 Online: 26 de Janeiro de 2012, 16:36 »
uma sugestão é vc utilizar um DS1307, que é um real time counter, com ele ligado ao microcontrolador vc programa a data que deseja como "agendada" e compara com o valor enviado pelo DS1307 ...

Offline Euclides Júnior

  • Júnior
  • Moderador
  • CNCMASTER
  • ******
  • Posts: 1941
  • Sexo: Masculino
  • O riso é a mecânica aplicada no ser vivo. Henri B.
  • Cidade - UF: Timoteo/MG
  • Nome:: Euclides de souza Lima Junior
  • Profissão: Projetista de maquinas industrial
Re:Contador regressivo
« Resposta #2 Online: 26 de Janeiro de 2012, 16:58 »
Eu baixo um template do flash, na net você acha alguns free, procuro em inglês  (countdown timer), depois faço as alterações no flash veja este em anexo que fiz
Abs.
Jr.

Offline neuronio

  • Novato
  • *
  • Posts: 23
  • Sexo: Masculino
  • No meio da dificuldade encontra-se a oportunidade.
    • Genoma Digital
  • Nome:: Neuronio
  • Profissão: Tec. Automacao
Re:Contador regressivo
« Resposta #3 Online: 26 de Janeiro de 2012, 18:32 »
Qual microcontrolador você deseja utilizar? PIC, ARDUINO, MOTOROLA?
Tem preferência de linguagem?

Achei alguma coisa com arduino utilizando DS1307 como Blackmore disse, e concordo que seria a melhor opção.

O link http://doityourselfchristmas.com/forums/showthread.php?17039-Simple-Arduino-christmas-countdown

Já deve ti ajudar em alguma coisa.

Falow, T+!

Código: [Selecionar]
/*
 Event countdown to a specified date(or time) using the ds1307
 
 */

#include "Wire.h"
#include <MsTimer2.h>
#define DS1307_I2C_ADDRESS 0x68
byte yearA;
byte monthA;
long days;
long daysf;
const int Disp1 = 4;                  // setting up the pins for the displays
const int Disp2 = 3;
const int Disp3 = 2;
const int segA = 5;
const int segB = 6;
const int segC = 7;
const int segD = 8;
const int segE = 9;
const int segF = 11;
const int segG = 10;
const int numDisplays = 3;
int digits[numDisplays] = {3, 2, 1};
const int displayPins[numDisplays] = {Disp1, Disp2, Disp3};
int digitCounter = 0;

void displayIsr() {
  digitalWrite(displayPins[digitCounter], HIGH);
  ++digitCounter;
  if (digitCounter == numDisplays) { digitCounter = 0; }
  number(digits[digitCounter]);
  digitalWrite(displayPins[digitCounter], LOW);
}

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers

void setDateDs1307(byte second,        // 0-59
byte minute,        // 0-59
byte hour,          // 1-23
byte dayOfWeek,     // 1-7
byte dayOfMonth,    // 1-28/29/30/31
byte month,         // 1-12
byte year)          // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));     
  Wire.send(decToBcd(dayOfWeek));
  Wire.send(decToBcd(dayOfMonth));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));
  Wire.send(00010000); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
  Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)

{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}

void setup()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  pinMode(Disp1, OUTPUT);
  pinMode(Disp2, OUTPUT);
  pinMode(Disp3, OUTPUT);
  digitalWrite(Disp1, HIGH);
  digitalWrite(Disp2, HIGH);
  digitalWrite(Disp3, HIGH);
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT); 
  Wire.begin();
  Serial.begin(9600);
 
 

  // Change these values to what you want to set your clock to.
  // and then comment out the setDateDs1307 call.
  //and upload sketch again

  second = 0;
  minute = 06;
  hour = 5;
  dayOfWeek = 3;
  dayOfMonth = 15;
  month = 9;
  year = 11;
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
 MsTimer2::set(1, &displayIsr);
 MsTimer2::start();

}



void loop()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  byte yearA;
  byte monthA;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  Serial.print(hour, DEC);// convert the byte variable to a decimal number when being displayed
  Serial.print(":");
  if (minute<10)
  {
      Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
      Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print("  Day of week:");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
  if (month <3) {//if month is January or February subtract 1 from year and use in yearA
      yearA=year-1;
    }
    else {
      yearA=year;
    }
    if (month <3) {//if month is January or February add 12 to the month and use in monthA
    monthA=month +12;
    }
    else {
    monthA=month;
    }
  //  Serial.println(dayOfWeek, DEC);
   delay(1000);
  /*The following calculates days to set countdown with the following formula
    If month is 1 or 2 add 12 to the month and subtract 1 from the year
    then apply the following formula
    365*year + year/4 - year/100 + year/400 + date + (153*month+8)/5 all integers rounded down
    Do this for the current date and the future date and subtract one from the other then
    display the days remaining on the 7 segment display*/
    days=365L*(yearA+2000L) + (2000L+yearA)/4L - (2000L+yearA)/100L + (2000L+yearA)/400L + dayOfMonth + (153L*monthA+8L)/5L;
    /* Below is the function to perform the calculation on the date till the event.
    I have set the now.year because I will always be counting down till the
    25th December in the current year. Just alter the year and month and day values
    for other dates*/
    daysf=365L*(year+2000L) + (2000L+year)/4L - (2000L+year)/100L + (2000L+year)/400L + 25L + (153L*12L+8L)/5L;
    unsigned int diff = daysf - days;
    digits[0] = diff%10;
    digits[1] = (diff >= 10) ? (diff/10)%10 : 10;
    digits[2] = (diff >= 100) ? (diff/100)%10 : 10;
    delay (500);
    Serial.println (days);
    Serial.println (daysf);
    Serial.println (diff);
}
 
void number(int var)
{
  switch(var)
  {
    case 0:
    digitalWrite(segG, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    break;
   
    case 1:
    digitalWrite(segA, HIGH);
    digitalWrite(segD, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, HIGH);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    break;
   
    case 2:
    digitalWrite(segC, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segD, LOW);   
    break;
   
    case 3:
    digitalWrite(segF, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    break;

    case 4:
    digitalWrite(segA, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segD, HIGH);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    break;
   
    case 5:
    digitalWrite(segB, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    break;   
   
    case 6:   
    digitalWrite(segB, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segG, LOW);
    break;
   
    case 7:
    digitalWrite(segF, HIGH);
    digitalWrite(segG, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segD, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    break;
   
    case 8:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;
   
    case 9:
    digitalWrite(segE, HIGH);
    digitalWrite(segG, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    break;
   
    case 10:
    digitalWrite(segE, HIGH);
    digitalWrite(segG, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segA, HIGH);
    digitalWrite(segB, HIGH);
    digitalWrite(segC, HIGH);
    digitalWrite(segD, HIGH);
    break;
    default:
    break;
   
  }
}
« Última modificação: 26 de Janeiro de 2012, 18:55 por F.Gilii »

Offline caipira

  • Novato
  • *
  • Posts: 9
  • Sexo: Masculino
  • GUIA-CNC
Re:Contador regressivo
« Resposta #4 Online: 26 de Janeiro de 2012, 19:17 »
O micro pode ser atmel ou pic.
Obrigado pelas respostas.
Abraço,
Carlos Lavrador

Offline neuronio

  • Novato
  • *
  • Posts: 23
  • Sexo: Masculino
  • No meio da dificuldade encontra-se a oportunidade.
    • Genoma Digital
  • Nome:: Neuronio
  • Profissão: Tec. Automacao
Re:Contador regressivo
« Resposta #5 Online: 26 de Janeiro de 2012, 20:06 »
Valeu F.Gilii !
Nem vi que cliquei em citar... rsrsrs

Offline caipira

  • Novato
  • *
  • Posts: 9
  • Sexo: Masculino
  • GUIA-CNC
Re:Contador regressivo
« Resposta #6 Online: 29 de Janeiro de 2012, 18:13 »
Qual microcontrolador você deseja utilizar? PIC, ARDUINO, MOTOROLA?
Tem preferência de linguagem?

Achei alguma coisa com arduino utilizando DS1307 como Blackmore disse, e concordo que seria a melhor opção.

O link http://doityourselfchristmas.com/forums/showthread.php?17039-Simple-Arduino-christmas-countdown

Já deve ti ajudar em alguma coisa.

Falow, T+!

Olá.
Não estou muito á vontade neste assunto, devo copiar este código para que microcontrolador?
O esquema que está no site só apresenta 3 displays, de que modo posso "ver" os dias, horas, minutos, etc...?
Obrigado pela atenção dispensada
Carlos Lavrador

Código: [Selecionar]
/*
 Event countdown to a specified date(or time) using the ds1307
 
 */

#include "Wire.h"
#include <MsTimer2.h>
#define DS1307_I2C_ADDRESS 0x68
byte yearA;
byte monthA;
long days;
long daysf;
const int Disp1 = 4;                  // setting up the pins for the displays
const int Disp2 = 3;
const int Disp3 = 2;
const int segA = 5;
const int segB = 6;
const int segC = 7;
const int segD = 8;
const int segE = 9;
const int segF = 11;
const int segG = 10;
const int numDisplays = 3;
int digits[numDisplays] = {3, 2, 1};
const int displayPins[numDisplays] = {Disp1, Disp2, Disp3};
int digitCounter = 0;

void displayIsr() {
  digitalWrite(displayPins[digitCounter], HIGH);
  ++digitCounter;
  if (digitCounter == numDisplays) { digitCounter = 0; }
  number(digits[digitCounter]);
  digitalWrite(displayPins[digitCounter], LOW);
}

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers

void setDateDs1307(byte second,        // 0-59
byte minute,        // 0-59
byte hour,          // 1-23
byte dayOfWeek,     // 1-7
byte dayOfMonth,    // 1-28/29/30/31
byte month,         // 1-12
byte year)          // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));     
  Wire.send(decToBcd(dayOfWeek));
  Wire.send(decToBcd(dayOfMonth));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));
  Wire.send(00010000); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
  Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)

{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}

void setup()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  pinMode(Disp1, OUTPUT);
  pinMode(Disp2, OUTPUT);
  pinMode(Disp3, OUTPUT);
  digitalWrite(Disp1, HIGH);
  digitalWrite(Disp2, HIGH);
  digitalWrite(Disp3, HIGH);
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT); 
  Wire.begin();
  Serial.begin(9600);
 
 

  // Change these values to what you want to set your clock to.
  // and then comment out the setDateDs1307 call.
  //and upload sketch again

  second = 0;
  minute = 06;
  hour = 5;
  dayOfWeek = 3;
  dayOfMonth = 15;
  month = 9;
  year = 11;
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
 MsTimer2::set(1, &displayIsr);
 MsTimer2::start();

}



void loop()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  byte yearA;
  byte monthA;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  Serial.print(hour, DEC);// convert the byte variable to a decimal number when being displayed
  Serial.print(":");
  if (minute<10)
  {
      Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
      Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print("  Day of week:");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
  if (month <3) {//if month is January or February subtract 1 from year and use in yearA
      yearA=year-1;
    }
    else {
      yearA=year;
    }
    if (month <3) {//if month is January or February add 12 to the month and use in monthA
    monthA=month +12;
    }
    else {
    monthA=month;
    }
  //  Serial.println(dayOfWeek, DEC);
   delay(1000);
  /*The following calculates days to set countdown with the following formula
    If month is 1 or 2 add 12 to the month and subtract 1 from the year
    then apply the following formula
    365*year + year/4 - year/100 + year/400 + date + (153*month+8)/5 all integers rounded down
    Do this for the current date and the future date and subtract one from the other then
    display the days remaining on the 7 segment display*/
    days=365L*(yearA+2000L) + (2000L+yearA)/4L - (2000L+yearA)/100L + (2000L+yearA)/400L + dayOfMonth + (153L*monthA+8L)/5L;
    /* Below is the function to perform the calculation on the date till the event.
    I have set the now.year because I will always be counting down till the
    25th December in the current year. Just alter the year and month and day values
    for other dates*/
    daysf=365L*(year+2000L) + (2000L+year)/4L - (2000L+year)/100L + (2000L+year)/400L + 25L + (153L*12L+8L)/5L;
    unsigned int diff = daysf - days;
    digits[0] = diff%10;
    digits[1] = (diff >= 10) ? (diff/10)%10 : 10;
    digits[2] = (diff >= 100) ? (diff/100)%10 : 10;
    delay (500);
    Serial.println (days);
    Serial.println (daysf);
    Serial.println (diff);
}
 
void number(int var)
{
  switch(var)
  {
    case 0:
    digitalWrite(segG, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    break;
   
    case 1:
    digitalWrite(segA, HIGH);
    digitalWrite(segD, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, HIGH);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    break;
   
    case 2:
    digitalWrite(segC, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segD, LOW);   
    break;
   
    case 3:
    digitalWrite(segF, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    break;

    case 4:
    digitalWrite(segA, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segD, HIGH);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    break;
   
    case 5:
    digitalWrite(segB, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    break;   
   
    case 6:   
    digitalWrite(segB, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segG, LOW);
    break;
   
    case 7:
    digitalWrite(segF, HIGH);
    digitalWrite(segG, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segD, HIGH);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    break;
   
    case 8:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;
   
    case 9:
    digitalWrite(segE, HIGH);
    digitalWrite(segG, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    break;
   
    case 10:
    digitalWrite(segE, HIGH);
    digitalWrite(segG, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segA, HIGH);
    digitalWrite(segB, HIGH);
    digitalWrite(segC, HIGH);
    digitalWrite(segD, HIGH);
    break;
    default:
    break;
   
  }
}

Offline Blackmore

  • CNCMASTER
  • ******
  • Posts: 1568
  • Sexo: Masculino
  • Profissão: Projetista Mecânico/Automação
Re:Contador regressivo
« Resposta #7 Online: 29 de Janeiro de 2012, 18:38 »
Citar
Não estou muito á vontade neste assunto, devo copiar este código para que microcontrolador?
O esquema que está no site só apresenta 3 displays, de que modo posso "ver" os dias, horas, minutos, etc...?

olha ... particularmente eu não gosto de postar códigos pelo simples fato de que é melhor ensinar a pescar do que entregar o peixe.
Mas já que o código está aí, interprete ele e veja o quê pode ser aproveitado para vc criar o seu próprio código, independente de fabricante, modelo ...
assim você poderá aprender mais até o ponto de ficar á vontade no assunto.
abraço!

Offline neuronio

  • Novato
  • *
  • Posts: 23
  • Sexo: Masculino
  • No meio da dificuldade encontra-se a oportunidade.
    • Genoma Digital
  • Nome:: Neuronio
  • Profissão: Tec. Automacao
Re:Contador regressivo
« Resposta #8 Online: 29 de Janeiro de 2012, 19:14 »
Como Blackmore disse este código vai te auxiliar a criar o seu próprio, você tem que analisar o código acima "ver como está estruturado" e implementar no seu. Ás vezes temos que pegar idéias de vários lugares e linguagens diferentes.

Citar
O esquema que está no site só apresenta 3 displays, de que modo posso "ver" os dias, horas, minutos, etc...?

Read more: http://www.guiacnc.com.br/microcontroladores/contador-regressivo/?action=post;last_msg=160282#ixzz1kspZBMKh

Você olhando o código verá que ele se aplica para display's de 7segmentos, você poderá trocá-lo e inserir um display LCD. Assim você pode escrever o que quiser.

Você tem algum simulador de eletrônica, como o Proteus? Ele facilita no desenvolvimento e no aprendizado.


Offline caipira

  • Novato
  • *
  • Posts: 9
  • Sexo: Masculino
  • GUIA-CNC
Re:Contador regressivo
« Resposta #9 Online: 30 de Janeiro de 2012, 09:40 »
É isso mesmo, estou a "montar" o esquema no Proteus e vou experimentar...
Obrigado,
Carlos Lavrador

Offline caipira

  • Novato
  • *
  • Posts: 9
  • Sexo: Masculino
  • GUIA-CNC
Re:Contador regressivo
« Resposta #10 Online: 03 de Fevereiro de 2012, 19:47 »
Converti o código acima referido para hexa, mas no Proteus dá erro!
Onde estarei a errar?
Obrigado,
Carlos Lavrador

Offline Blackmore

  • CNCMASTER
  • ******
  • Posts: 1568
  • Sexo: Masculino
  • Profissão: Projetista Mecânico/Automação
Re:Contador regressivo
« Resposta #11 Online: 04 de Fevereiro de 2012, 09:39 »
Citar
Converti o código acima referido para hexa, mas no Proteus dá erro!

qual o tipo de erro o ares?
quando vc compilou o file, os includes estavam disponíveis?
vc está utilizando um controlador compatível?
vc está utilizando o file .hex ou .cof?

Offline caipira

  • Novato
  • *
  • Posts: 9
  • Sexo: Masculino
  • GUIA-CNC
Re:Contador regressivo
« Resposta #12 Online: 04 de Fevereiro de 2012, 17:01 »
qual o tipo de erro o ares?
quando vc compilou o file, os includes estavam disponíveis?
vc está utilizando um controlador compatível?
vc está utilizando o file .hex ou .cof?

Converti o código (em *.txt) para *.hex com o programa HexConverter.
"Coloquei" o ficheiro *.hex no microcontrolador no Proteus, e depois do "play" deu erro (imagem em anexo)
Obrigado

Offline Blackmore

  • CNCMASTER
  • ******
  • Posts: 1568
  • Sexo: Masculino
  • Profissão: Projetista Mecânico/Automação
Re:Contador regressivo
« Resposta #13 Online: 05 de Fevereiro de 2012, 14:44 »
Citar
Converti o código (em *.txt) para *.hex com o programa HexConverter.

não sou conhecedor profundo mas eu entendo que seu procedimento não está certo, então eu recomendo que você procure entender melhor o que é e como programar um controlador, entenda como é e para que serve a configuração, programação e tb usar um bom compilador de acordo com o microcontrolador escolhido, pois compilar não é pura e simplesmente converter de .* para .HEX ... mas existe um certo roteiro seguido pelo compilador e este faz a conversão para o "entendimento" do controlador, cada um com sua particularidade ... MicroCHIP, Freescale, NXP, Atmel, Renesas, Texas entre tantos outros.
Se alguém que tenha mais experiência (converter direto de ASM ou C para .HEX)  puder e quiser explicar melhor tudo isso eu ficaria grato em entender melhor como tudo isso funciona.

Offline minilathe

  • How to ask questions - The Smart Way...
  • Moderadores
  • CNCMASTER
  • ******
  • Posts: 4295
  • Sexo: Masculino
  • http://science-lakes.com/article43-html.html
  • Cidade - UF: Rio de Janeiro - RJ
  • Nome:: Gil Pinheiro
  • Profissão: Engenheiro e professor universitário
Re:Contador regressivo
« Resposta #14 Online: 05 de Fevereiro de 2012, 16:39 »
Se alguém que tenha mais experiência (converter direto de ASM ou C para .HEX)  puder e quiser explicar melhor tudo isso eu ficaria grato em entender melhor como tudo isso funciona.

O arquivo hex é um arquivo em formato texto que contém o programa em linguagem de máquina convertido nesse formato texto (geralmente usando o código ASCII). Para se obter um arquivo hex não basta converter o texto de um programa em C ou em Assembly no formato hex.

A sequência de operações para gerar um arquivo hex é a seguinte:
1-Gerar ou obter o programa, também chamado de código fonte. Em alguma linguagem para computadores, como C, Assembly, Basic, ....
2-Compilar o programa usando um programa compilador (exe.: gcc do Linux) ou usando um ambiente integrado de desenvolvimento (IDE), que contém um compilador.
3-Linkar o programa compilado no passo 2 usando o programa compilador (exe.: gcc do Linux) ou usando um ambiente integrado de desenvolvimento (IDE), que contém um linkeditor. Essa fase de Linkedição pode ter como saída os arquivo asm, lst, cof e hex.
4-Carregar o arquivo hex no microcontrolador real ou num microcontrolador simulado (ex. Proteus).

Veja que não há conversão para hex. Me parece que as etapas 2 e 3 não foram executadas, não é? As etapas 2 e 3 devem ser executadas por compiladores específicos para o processador. Por exemplo, não posso usar o gcc de um Linux para PC para compilar o programa de um PIC.

« Última modificação: 05 de Fevereiro de 2012, 16:42 por minilathe »

 

/** * */