Cheatsheet SuP
Cheatsheet SuP
Cheatsheet SuP
unsigned char numere_7seg[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; // 0 - 9 pe 7seg display
void setDigit(int cifra) // functia care scrie pe display, primeste ca parametru cifre 0 - 9
{
LATD = SPI_read(numere_7seg[cifra]);
}
void SPI_init()
{
TRISCbits.SPI1_CLK = 0;
TRISCbits.SPI1_SDO = 0;
}
void SPI_open()
{
//Fosc/64
SSPM3 = 0;
SSPM2 = 0;
SSPM1 = 1;
SSPM0 = 0;
CKE = 1;
CKP = 0;
SMP = 0;
SSPEN = 1; //Serial port enable(0 = porturi sincrone oprite, 1 = pornite)
}
void SPI_close()
{
SSPEN = 0;
}
// delay de n secunde
void waitSeconds(float n)
{
for (int i = 1; i <= (n * 100); i++)
__delay_ms(10);
}
// OUTPUT PINI
TMR1IE = 1; // TMR1 Overflow Interrupt Enable bit; 1 = Enables the TMR1 overflow interrupt
TMR1IF = 0; // 0 = TMR1 register did not overflow
TMR1IP = 0; // TMR1 Overflow Interrupt Priority bit; 0 = Low priority | 1 = High priority
TMR1H = 0; // TMR1H Timer1 Register High Byte
TMR1L = 0; // TMR1L Timer1 Register Low Byte
TMR1ON = 1; // Timer1 can be enabled or disabled by setting or clearing control bit, TMR1ON (T1CON<0>).
TMR2IE = 1; // TMR2 to PR2 Match Interrupt Enable bit; 1 = Enables the TMR2 to PR2 match interrupt
TMR2IF = 0; // TMR2 to PR2 Match Interrupt Flag bit; 0 = No TMR2 to PR2 match occurred
TMR2IP = 1; // TMR2 to PR2 Match Interrupt Priority bit; 1 = High priority
When TMR2 (TMR4) is equal to PR2 (PR4), the following three events occur on the next increment cycle:
• TMR2 (TMR4) is cleared
• The CCPx pin is set (exception: if PWM duty cycle = 0%, the CCPx pin will not be set)
• The PWM duty cycle is latched from CCPRxL into CCPRxH
*/
//Aliniere la dreapta
ADFM = 1;
// ADFM: A/D Result Format Select bit
// 1 = Right justified
// 0 = Left justified
// F = Fosc/32
// TADC = 8us
ADCS2 = 0;
ADCS1 = 1;
ADCS0 = 0;
/*
ADCS<2:0>: A/D Conversion Clock Select bits
111 = FRC (clock derived from A/D RC oscillator)(1)
110 = FOSC/64
101 = FOSC/16
100 = FOSC/4
011 = FRC (clock derived from A/D RC oscillator)(1)
010 = FOSC/32
001 = FOSC/8
000 = FOSC/2
*/
ADRESH = 0;
ADRESL = 0;
__delay_ms(1);
ADON = 1;
}