Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<reg51.h>
- #define true 1
- #define false 0
- sbit button = P1^0; //Botão de pressão: 1 Botão livre, 0 Botão precionado
- sbit led = P1^7; //Led: 1 Led OFF, 0 Led ON
- void delay_ms(unsigned int ms_count) //Função de delay
- {
- unsigned int i,j;
- for(i=0; i<ms_count; i++)
- {
- for(j=0; j<100; j++);
- }
- }
- int debounce() //Função de debounce retorna: 1 Sucesso, 0 Insucesso
- {
- delay_ms(100);
- return (button == 0) ? 1 : 0;
- }
- void main()
- {
- unsigned char display[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
- int k = 0;
- bit seven_seg = false;
- button = 1; //Definir pino de input
- P2 = display[k]; //Colocar o display com o numero zero
- led = 1; //Led OFF
- while(button == 0); //Certificação que o botão se encontra libertado ao iniciar
- while(1)
- {
- if(button == 0 && seven_seg == false) //Verifica se o uilizador premiu o botão e se o display se encontra pronto para ser atualizado
- {
- if(debounce() == 1)
- {
- k = (k < 15) ? k+1 : 0; //Verifica se o último índice do array foi atingido se sim display a 0
- P2 = display[k]; //Atualiza o display
- led = (k > 8) ? 0 : 1; //Verifica se o numero no display é igual ou superior a 8 se sim Led ON
- seven_seg = true; //Display atualizado
- }
- }
- if(button == 1) //Libertou o botão?
- seven_seg = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement