Skip to content

Instantly share code, notes, and snippets.

View Nemweb's full-sized avatar

Stephen Nemweb

View GitHub Profile
@Nemweb
Nemweb / velha.c
Last active September 3, 2018 23:04
// PIC16F628A Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled)
@Nemweb
Nemweb / ShiftRegisterSPI.c
Last active October 29, 2017 13:28
Example code of 74HC595 shift-register control via SPI with PIC18F2550
// PIC18F2550 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config PLLDIV = 5 // PLL Prescaler Selection bits (Divide by 5 (20 MHz oscillator input))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1 // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
// CONFIG1H
@Nemweb
Nemweb / ADC.h
Created February 25, 2017 20:17
unsigned ADC_Read(unsigned short channel)
{
ADCON0 &= 0x03;
ADCON0 |= (channel << 2);
delay_us(30);
GO_nDONE = 1;
while (GO_nDONE);
return ((ADRESH << 8) + ADRESL);
}
void delay_ms(unsigned int delay)
{
for(;delay > 0; delay--)
{
__delay_ms(1);
}
}
void delay_us(unsigned int delay)
{
// PIC18F2550 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config PLLDIV = 12 // PLL Prescaler Selection bits (Divide by 12 (48 MHz oscillator input))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1 // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
@Nemweb
Nemweb / PSpseudo.c
Last active October 16, 2017 16:31
posição_ordenada = 0;
while(posição_ordenada != tamanho_do_vetor)
{
menor = vetor[posição_ordenada];
posição_do_menor = posição_ordenada;
for(i = posição_ordenada+1; i < tamanho_do_vetor; i++)
{
if(vetor[i] < menor)
{
menor = vetor[i];
while(feito == 0)
{
feito = 1;
for(i = 0; i < tamanho_do_vetor; i++)
{
if(vetor[i] > vetor[i+1])
{
troca(vetor[i], vetor[i+1]);
feito = 0;
}