unsigned char tc_tecla(unsigned int timeout) { unsigned int to=0; unsigned char i; unsigned char ret=0; unsigned char tmp=PORTB; while(((to < timeout)||(!timeout))&&(!ret)) { for(i=0;i<3;i++) { PORTB|=~linha[i]; if(!TC1){delay1ktcy(2*20);if(!TC1){while(!TC1);ret= 1+i;break;}}; if(!TC2){delay1ktcy(2*20);if(!TC2){while(!TC2);ret= 4+i;break;}}; if(!TC3){delay1ktcy(2*20);if(!TC3){while(!TC3);ret= 7+i;break;}}; if(!TC4){delay1ktcy(2*20);if(!TC4){while(!TC4);ret= 10+i;break;}}; PORTB &=linha[i]; }; delay1ktcy(2*5); to+=5; } if(!ret)ret=255; if(ret == 11)ret=0; PORTB=tmp; return ret; }
void lcd_dat(unsigned char val) { LENA=1; lcd_wr(val); LDAT=1; delay1ktcy(2*3); LENA=0; delay1ktcy(2*3); LENA=1; }
/* * INITIALIZATION AND MISC */ void setup_1(void) { uint8_t i; IFI_Initialization(); /* Initialize serial port communication. */ statusflag.b.NEW_SPI_DATA = 0; usart1_open(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, kBaud115); delay1ktcy(50); /* Make the master control all PWMs (for now) */ txdata.pwm_mask.a = 0xFF; for (i = IX_DIGITAL(1); i <= IX_DIGITAL(CT_DIGITAL); ++i) { digital_setup(i, false); } /* Init ADC */ /* Setup the number of analog sensors. The PIC defines a series of 15 * ADC constants in mcc18/h/adc.h that are all of the form 0b1111xxxx, * where x counts the number of DIGITAL ports. In total, there are * sixteen ports numbered from 0ANA to 15ANA. */ if (NUM_ANALOG_VALID(USER_CT_ANALOG) && USER_CT_ANALOG > 0) { /* ADC_FOSC: Based on a baud_115 value of 21, given the formula * FOSC/(16(X + 1)) in table 18-1 of the PIC18F8520 doc the * FOSC is 40Mhz. * Also according to the doc, section 19.2, the * ADC Freq needs to be at least 1.6us or 0.625MHz. 40/0.625=64 * (Also, see table 19-1 in the chip doc) */ #if defined(MCC18) OpenADC( ADC_FOSC_64 & ADC_RIGHT_JUST & ( 0xF0 | (16 - USER_CT_ANALOG) ) , ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ); #elif defined(SDCC) adc_open( ADC_CHN_0, ADC_FOSC_64, ADC_CFG_16A, ADC_FRM_RJUST | ADC_INT_OFF | ADC_VCFG_VDD_VSS ); #else #error "Bad Comp" #endif } else { /* TODO: Handle the error. */ puts("ADC is disabled"); } }
void lcd_init(void) { LENA=0; LDAT=0; delay1ktcy(2*20); LENA=1; lcd_cmd(L_CFG); delay1ktcy(2*5); lcd_cmd(L_CFG); delay1ktcy(2*1); lcd_cmd(L_CFG); //configura lcd_cmd(L_OFF); lcd_cmd(L_ON); //liga lcd_cmd(L_CLR); //limpa lcd_cmd(L_CFG); //configura lcd_cmd(L_L1); }
void main(void) { uint8_t i; TRISB = 0; // Pins as output LATB = 0; // LEDs off while (1) { for (i = 0; i < 10; i++) { LATB = number_to_7seg(i); delay1ktcy(250); //1s @ 1MHz } } }