Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include<reg51.h>
  2.  
  3. #define true 1
  4. #define false 0
  5.  
  6. sbit button = P1^0; //Botão de pressão: 1 Botão livre, 0 Botão precionado
  7. sbit led = P1^7; //Led: 1 Led OFF, 0 Led ON
  8.  
  9. void delay_ms(unsigned int ms_count) //Função de delay
  10. {
  11. unsigned int i,j;
  12.  
  13. for(i=0; i<ms_count; i++)
  14. {
  15. for(j=0; j<100; j++);
  16. }
  17. }
  18.  
  19. int debounce() //Função de debounce retorna: 1 Sucesso, 0 Insucesso
  20. {
  21. delay_ms(100);
  22. return (button == 0) ? 1 : 0;
  23. }
  24.  
  25. void main()
  26. {
  27. unsigned char display[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
  28. int k = 0;
  29. bit seven_seg = false;
  30.  
  31. button = 1; //Definir pino de input
  32. P2 = display[k]; //Colocar o display com o numero zero
  33. led = 1; //Led OFF
  34.  
  35. while(button == 0); //Certificação que o botão se encontra libertado ao iniciar
  36.  
  37. while(1)
  38. {
  39. if(button == 0 && seven_seg == false) //Verifica se o uilizador premiu o botão e se o display se encontra pronto para ser atualizado
  40. {
  41. if(debounce() == 1)
  42. {
  43. k = (k < 15) ? k+1 : 0; //Verifica se o último índice do array foi atingido se sim display a 0
  44. P2 = display[k]; //Atualiza o display
  45. led = (k > 8) ? 0 : 1; //Verifica se o numero no display é igual ou superior a 8 se sim Led ON
  46. seven_seg = true; //Display atualizado
  47. }
  48. }
  49.  
  50. if(button == 1) //Libertou o botão?
  51. seven_seg = false;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement