Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <16f883.h>
- #use fast_io(a)
- #use fast_io(b)
- #use fast_io(c)
- #fuses HS,WDT,PROTECT,NOLVP,NODEBUG,NOMCLR,NOBROWNOUT
- #use delay(clock=10000000)
- #use RS232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,errors,stream=PORTA,RESTART_WDT)
- /*
- Notas:
- Pino 1 PORTC Como entrada
- Pino 1,2,3,4,5 PORTB como saída
- Startbyte =#
- */
- int16 i=0;
- int8 dimming; //0-> 100%, 1-> 75%, 2-> 50%, 3-> 25%
- //output_a(0x00);
- Unsigned int8 StartByte='#';
- Unsigned int8 Data_Buffer[9];
- int8 data_receive=0;
- int8 current_data=0;
- int8 BufferOK=0;
- int8 modo=0;
- //Rotina de Interrupção do Pino RX
- #INT_RDA
- void trata_INT_RDA()
- {
- data_receive=fgetc(PORTA); // Recebo o comando da porta Serie
- if(data_receive==StartByte) //
- {
- //TimeOut=0;
- //count_TimerA=0;
- current_data=0;
- Data_Buffer[current_data]=data_receive;
- current_data++;
- BufferOK=0;
- }
- else
- {
- if(current_data==8 || data_receive==13) // || Timeout
- {
- Data_Buffer[current_data]=data_receive;
- current_data=0;
- bufferOK=1;
- if(data_receive!=13) //erro
- bufferOK=0;
- }
- else
- {
- Data_Buffer[current_data]=data_receive;
- current_data++;
- }
- }
- }
- restart_wdt();
- // Separar e utilizar a mensagem recebida por RS232
- void trata_buffer()
- {
- switch(Data_Buffer[1])
- {
- case 'M':
- if(Data_Buffer[2]=='1')
- {
- modo=0;
- //write eeprom
- }
- if(Data_Buffer[2]=='2')
- {
- modo=1;
- }
- if(Data_Buffer[2]=='3'&& Data_Buffer[3]=='\n')
- {
- modo=2;
- }
- if(Data_Buffer[2]=='4')
- {
- dimming=3;
- }
- break;
- /* case 'D':
- if(
- */
- }}
- restart_wdt();
- void main()
- {
- set_tris_a(0b00110011);
- set_tris_c(0b10100000); //Coloca o RC5 como input
- set_tris_b(0x00); // Coloca todo o Porto B como Output
- setup_adc(ADC_OFF);
- enable_interrupts(INT_RDA);
- enable_interrupts(global);
- //SETUP_TIMER_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_1);
- Setup_wdt(WDT_2304MS);
- restart_wdt();
- output_low(PIN_B1); //Start test
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- restart_wdt();
- while(true)
- {
- restart_wdt();
- if(bufferOK=1)
- {
- delay_ms(2);
- trata_buffer();
- bufferOK=0;
- }
- restart_wdt();
- if(input(PIN_C5)) // Caso o relogio tenha ativado modo NOITE
- {
- Dimming=0;
- }
- restart_wdt();
- if(modo=='0')
- {
- output_high(PIN_B1); //Start test
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- delay_ms(1000);
- output_low(PIN_B1); //Start test
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- }
- if(modo=='1')
- {
- output_high(PIN_B1); //Start test
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- output_low(PIN_B1); //Start test
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- }
- restart_wdt();
- /*
- switch (modo)
- {
- case '0':
- output_high(PIN_B1); //Start test
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- break;
- case '1':
- output_high(PIN_B1); //Start test
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- delay_ms(1000);
- output_low(PIN_B1); //Start test
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- break;
- case '2':
- for(i=0;i<100;i++)
- {
- output_high(PIN_B1); //Start test
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- delay_ms(150);
- output_low(PIN_B1); //Start test
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- }
- break;
- } */
- restart_wdt();
- switch(Dimming){
- case 0:
- for(i=0;i<100;i++) //Dimming 30% (T=10ms) f=100Hz
- {
- output_high(PIN_B1);
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- delay_ms(4);
- output_low(PIN_B1);
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- delay_ms(9);
- }
- break;
- case 1:
- for(i=0;i<100;i++) //Dimming 20% (T=10ms) f=100Hz
- {
- output_high(PIN_B1);
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- delay_ms(2);
- //delay_us(500);
- output_low(PIN_B1);
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- delay_ms(8);
- //delay_us(500);
- }
- break;
- case 2:for(i=0;i<100;i++) //Dimming 10% (T=10ms) f=100Hz
- {
- output_high(PIN_B1);
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- delay_ms(1);
- // delay_us(500);
- output_low(PIN_B1);
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- delay_ms(9);
- // delay_us(500);
- }
- break;
- case 3:for(i=0;i<100;i++) //Dimming 5% (T=10ms) f=100Hz
- {
- output_high(PIN_B1);
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- delay_ms(1);
- // delay_us(500);
- output_low(PIN_B1);
- output_low(PIN_B2);
- output_low(PIN_B3);
- output_low(PIN_B4);
- output_low(PIN_B5);
- delay_ms(9);
- // delay_us(500);
- }
- break;
- default: output_high(PIN_B1); //Dimming 100%
- output_high(PIN_B2);
- output_high(PIN_B3);
- output_high(PIN_B4);
- output_high(PIN_B5);
- delay_ms(1000);
- break;
- }
- }//fim while(true) 1
- }//fim main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement