Pesquisar neste blog

14/03/2023

Animação com texto usando CSS

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="refresh" content="3">
    <title>Campo elemento</title>
   
       
    <style>
        #container{
            background-color: #000;

        }
        h1{
            -webkit-text-stroke: .5vh #fff;
            font-size: 30vw;
            font-weight: bold;
            text-align: center;
            text-transform: uppercase;
            background-image: url(img/energisa.jpg);
            background-clip: text;
            -webkit-background-clip: text;
            color: transparent;
            animation: text 10s ease alternate infinite;
        }
        @keyframes text{
            from{
                background-position: 0% 50%;
            }
            to{
                background-position: 100% 50%;
            }
        }
        .scale{
            transform: scale(1);
        }
    </style>
         
</head>

<body id="container">
    <div>
        <h1>Like !</h1>
    </div>
</body>
</html>

Saída gerada



13/03/2023

Imagem refletida com CSS

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="refresh" content="5">
    <title>Imagem refletida</title>
    <link rel="stylesheet" type="text/css" href="estilo.css">

<style>
    .imagem{
    position: relative;
    width: 200px;
    height: 200px;
    border-radius: 20px;
    background: url(https://cdn.britannica.com/66/80466-050-2E125F5C/Arc-de-Triomphe-Paris-France.jpg?w=300) center;
    background-size: cover;
}
.imagem::before, .imagem::after{
    content: '';
    width: 100%;
    height: 100%;
    bottom: -220px;
    border-radius: inherit;
    position: absolute;
}
.imagem::before{
    background: inherit;
    opacity: .6;
    transform: scaleY(-1);
}
.imagem::after{
    background: linear-gradient(0deg, #fff,
     sT, #FFF0 100%);

}
</style>
</head>
<body>
    <div class="imagem"></div>
</body>
</html>

Saída gerada















12/03/2023

Limitar o campo da escrita em CSS

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="refresh" content="3">
    <title>Campo elemento</title>
   
       
    <style>
        h1{
            width: 400px;
            border: 3px solid;
           
            white-space: nowrap;/*no final não quebre a linha*/
            overflow: hidden; /*se passar do limite vai esconder*/
            text-overflow: ellipsis; /*se passar coloca ...*/

        }
        .scale{
            transform: scale(1);
        }
    </style>
         
</head>

<body>
    <h1>Seja bem vindo ao Blog da Engenharia Codidiana</h1>
</body>
</html>

Saída gerada









Palavras chave:

Limit the field of writing in CSS
CSS дээр бичих талбарыг хязгаарлах
په CSS کې د لیکلو ساحه محدوده کړئ
Limit di fild fɔ rayt insay CSS
سی ایس ایس میں لکھنے کے شعبے کو محدود کریں۔
הגבל את תחום הכתיבה ב-CSS
Piirake CSS-is kirjutamisvälja
Begränsa fältet för att skriva i CSS

Prova 1 #2022/1

1.1. Crie um programa e faça as ligações necessárias para que os LED liguem e desliguem com frequências iguais as indicadas a seguir:

LED1 = 5Hz         Vi >= 0 e Vi  < 0,8v
LED2 = 10Hz         Vi >= 0,8 e Vi < 1,6v
LED3 = 20Hz         Vi >= 1,6 e Vi < 2,4v
LED4 = 50Hz         Vi >= 2,4 e Vi < 3,2v
LED5 = 100Hz Vi >= 3,2 e Vi < 4v
LED6 =                    Liga quando Vi >= 4v














Resolução feita no CCS C Compiler

#include <16F877A.h>
#device adc = 8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT, NOWRT
#use delay(clock = 20MHz)
#include <lcd.c>
#use standard_io (b)
/*Crie um programa e faça as ligações para que os LED liguem e desliguem com 
frequências iguais as indicadas a seguir:
LED1 = 5HZz Vi >= 0V e Vi < 0,8V
LED2 = 10Hz Vi >= 0,8V e Vi < 1,6V
LED3 = 20HZ Vi >= 1,6 e Vi < 2,4V
LED4 = 50HZ Vi >= 2,4 e Vi < 3,2V
LED5 = 100HZ Vi >= 3,2 e Vi < 4V
LED6 = Liga quando Vi >= 4V
*/
unsigned int8 analog, frequencia, tempo;
float tensao;
unsigned int16 cont0 = 0, cont1 = 0, cont2 = 0, cont3 = 0, cont4 = 0, cont5 = 0;

#int_TIMER0
void TIMER0_isr(float tensao){
         
   if(tensao >= 0.01 && tensao < 0.8){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 5 Hz", tensao);      
      if(++cont1 >= 1970) {cont1 = 0; output_toggle(PIN_B0);}   // 5HZ   ok
      
   }else if(tensao >= 0.80 && tensao < 1.60){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 10 Hz", tensao); 
      if(++cont2 >= 750) {cont2 = 0; output_toggle(pin_B1);}   //10 HZ  ok
      
   }else if(tensao >= 1.60 && tensao < 2.40){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 20 Hz", tensao); 
      if(++cont3 >= 240) {cont3 = 0; output_toggle(pin_B2);}   // 20 Hz  
      
   }else if(tensao >= 2.40 && tensao < 3.20){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 50 Hz", tensao); 
      if(++cont4 >= 98) {cont4 = 0; output_toggle(pin_B3);}   // 50 Hz
      
   }else if(tensao >= 3.20 && tensao < 4.0){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 100 Hz", tensao); 
      if(++cont5 >= 39) {cont5 = 0; output_toggle(pin_B4);}    // 100 Hz
   }else if(tensao >= 4.0){
      output_high(PIN_B5);
   }
   
}

void main(){
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);   
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED, 0, 1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_adc(ADC_CLOCK_DIV_32);           // Set ADC conversion time to 32Tosc
   setup_adc_ports(AN0);          // Configure AN0,AN1 and AN3 as analog   
   set_adc_channel(0);                    // Select channel AN1     
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   lcd_init();
   
   while(true) {
      analog = read_adc();
      tensao = (5.0 / 255.0) * analog;
      printf(lcd_putc,"\fTENSAO = %1.2f V\nT= %ums \tFREQ= %uHz",tensao, tempo, frequencia);
            
      TIMER0_isr(tensao);
            
   }
}


















































2. 2. Crie um programa e faça as ligações (cristal, resistor, alimentação, ...) necessárias para que os displays apresentem uma luz circulante no sentido horário (a, b, c, d, d', e', f', a', a, b,...). Onde d', e', f' e a', são segmento do display  catodo comum. A velocidade dependerá da posição do potenciômetro.















Resolução em código feito no CCS C Compiler

#include <16F877A.h>
#device adc = 8
#use delay(clock = 20MHz)
#FUSES HS,NOWDT,NOPROTECT,NOLVP

unsigned int8 vet1[] = {0b00001000, 0b00010000, 0b00100000, 0b00000001};
unsigned int8 vet2[] = {0b11111110, 0b11111101, 0b11111011, 0b11110111};

int size = sizeof(vet1)/sizeof(int); // tamanho do vetor vet1
unsigned int16 leia;

void main(void){
  setup_adc(ADC_CLOCK_DIV_32);           // Set ADC conversion time to 32Tosc
  setup_adc_ports(AN0_AN1_AN3);          // Configure AN0,AN1 and AN3 as analog
  setup_ccp2(CCP_PWM);                   // Configure CCP2 as a PWM
  setup_timer_2(T2_DIV_BY_16, 255, 1);   // Set PWM frequency to 488Hz
  set_adc_channel(0);                    // Select channel AN1
  
  while(true){
                        
      leia = read_adc();                 // Read from AN1 and store in j
      
      for(int i = 0; i < size; i++){
         output_d(vet1[i]);
         delay_ms(leia);
      }      
      
      for(int j = 0; j < size; j++){
         output_d(vet2[j]);
         delay_ms(leia);
      }
   }
}




3. Desenvolva um programa para acionar o motor de passo a seguir. Para girar no sentido 1 (b1, b2, b3, b4, b1, b2,...) e no sentido contrário devem ser acionadas as bobinas (b4, b3, b2, b1, b4, b3,...) Utilize um botão para inverter o sentido. O motor deve girar com velocidade de 100 rpm (rpm = rotações por minuto) no sentido horário e 75 rpm no sentido anti-horário.













Resolução feita no CCS C Compiler

#include <16F877A.h>
#fuses XT, HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 20MHz)
#include <lcd.c>

#define t1 150
#define t2 200

#use fast_io(B)

unsigned int horario[9] = {0b00010000, 0b00110000, 0b01110000, 0b01100000, 0b11100000, 0b11000000, 0b10000000, 0b10010000};
unsigned int antiHorario[9] = {0b10000000, 0b11000000, 0b01000000, 0b01100000, 0b00100000, 0b00110000, 0b00010000, 0b10010000};
int i = 0, cont = 0;

#INT_EXT
ext_isr(){
   cont++;
   if(cont >= 4) {cont = 0;}
}

void main(){
   set_tris_b(0x01);
   output_low(PIN_B7);
   port_b_pullups(TRUE);
   enable_interrupts(int_ext);
   ext_int_edge(L_TO_H);
   enable_interrupts(GLOBAL);
   
   lcd_init();
   
   while(true){
      printf(lcd_putc, "\fMOTOR OFF !");
      delay_ms(500);
   
      while(cont == 1){
         output_b(horario[i]);
         lcd_gotoxy(1, 1);
         delay_ms(t1);
         i++;
         if(++i >= 8) {i = 0;}
         
         lcd_gotoxy(1, 1);
         printf(lcd_putc, "\fMOTOR ON");
         lcd_gotoxy(1,2);
         printf(lcd_putc, "SENTIDO HORARIO");
         lcd_gotoxy(21,1);
         printf(lcd_putc, "Freq = 100 RPM");
         lcd_gotoxy(21,2);
         printf(lcd_putc, "Freq = 10.47 rad/s");
      }
   
      while(cont == 3){
         output_b(antiHorario[i]);
         delay_ms(t2);
         i++;
         if(++i >= 8) {i = 0;}
         
         lcd_gotoxy(1, 1);
         printf(lcd_putc, "\fMOTOR ON");
         lcd_gotoxy(1,2);
         printf(lcd_putc, "SENTIDO ANTI-HORARIO");
         lcd_gotoxy(21,1);
         printf(lcd_putc, "Freq = 75 RPM");
         lcd_gotoxy(21,2);
         printf(lcd_putc, "Freq = 7.85 rad/s");
      }
   }
}

Software Proteus versão 7.9
























10/03/2023

Comunicação serial com PIC 16F628A e 18F4550

Código feito em CCS C Compiler

Arquivo: 16F628A.c

#include <16F628A.h>
#fuses INTRC, NOWDT, NOMCLR
#use delay(clock = 4MHz)

#use rs232(baud= 9600, xmit= PIN_B2, rcv= PIN_B1)

void main(){
   
   int1 btn1, btn2, btn3;
   
   while(true){
      btn1 = input(PIN_A0);
      btn2 = input(PIN_A1);
      btn3 = input(PIN_A2);
      
      if( btn1 == 1 && btn2 == 0 && btn3 == 0 ){
         printf("#AUTO");
         
      }else if( btn1 == 0 && btn2 == 1 && btn3 == 0 ){
         printf("#ECONOMICO");
         
      }else if( btn1 == 0 && btn2 == 0 && btn3 == 1 ){
         printf("#DESEMPENHO");
         
      }
      
      delay_ms(1000);
   }
}


Arquivo: 18F4550.c

#include <18F4550.h>
#fuses INTRC, NOWDT, NOMCLR
#use delay(clock = 4MHz)

#use rs232(baud = 9600, xmit= PIN_C6, rcv= PIN_C7)
#include <lcd.c>

#INT_RDA
void serial_init(){
   char temp;
   
   while( kbhit() ){ // verificar se tem dados no banco
      temp = getc();
      if( temp == '#'){
         printf( LCD_PUTC, "\f");
      }else {
         printf(LCD_PUTC, "%c", temp);
      }
   }
}

void main(){
   
   lcd_init();
   
   enable_interrupts( GLOBAL );
   enable_interrupts( INT_RDA);
   
   printf( LCD_PUTC, "\fINICIANDO ...");
   delay_ms(1000);
   
   while(TRUE){
      
   }
}

Saída gerada no Proteus







09/03/2023

Comunicação serial com PIC 18F4550

Código feito em CCS C Compiler

#include <18F4550.h>
#fuses INTRC, NOWDT, NOMCLR
#use delay(clock = 4MHz)

// diretiva rs232, velocidade 9600, pino de transmisão, pino de recebimento
#use rs232(baud = 9600, xmit= PIN_C6, rcv= PIN_C7) 

//diretiva de interrupção da comunicação serial
#INT_RDA
void serial_int(){
   char temp;
   //enquanto estiver dados na leitura disponível
   while ( kbhit()) { // funcão retorna 1 se estiver disponível e 0 caso contrário
      temp = getc();    // fazendo a leitura do dado no bufer serial
      
      if (temp == 'L'){
         output_bit(PIN_D0, 1);
         printf("-> LIGOU !");
      }
      if (temp == 'D'){
         output_bit(PIN_D0, 0);
         printf("-> DESLIGOU !");
      }
   }
}

void main(){
   
   enable_interrupts( GLOBAL ); // habilita a interrupção global
   enable_interrupts( INT_RDA );
   
}

Saída gerada no Proteus



08/03/2023

Logotipo do instagram em HTML

Objetivo: Gerar o logotipo do Instagram em HTML com CSS

Saída gerada



























<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Logo da Instagram</title>
   
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
    rel="stylesheet"
    integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
    crossorigin="anonymous">

    <style>
      div {
        margin: 20px;
        width: 20rem;
        height: 20rem;
        color: #fff;
        background: radial-gradient(circle at 33% 100%,
        #fed373 4%,
        #f15245 30%,
        #d92e7f 62%,
        #9b36b7 85%,
        #515ecf

    );
    border-radius: 30%;
    position: relative;
}

.d1{
    content: none;
    border: 1rem solid;
    border-radius: 30%;
    width: 12.5rem;
    height: 12.5rem;
    position: absolute; /* nas 4 direções */
    inset: 0;
    margin: auto;
}

.d2{
    content: normal;
    border: 1rem solid;
    border-radius: 100%; /* arredonda a borda em raio */
    width: 5rem;
    height: 5rem;
    position: absolute; /*posição fixa da tela*/
    inset: 0;   /*posicionamento */
    margin: auto;
}

span{
    border: 1rem solid;
    border-radius: 100%;
    position: absolute;
    top: -7rem; /*espaço acima do*/
    right: -5rem ;
}  
    </style>
</head>

<body>
    <div >
        <div class="d1">
            <span class="d2">
                <span></span>
            </span>
        </div>
    </div>
   
    <div>
        <div class="d1">
            <div class="d2">
                <span></span>
            </div>
        </div>
    </div>
</body>
</html>

Memória eeprom com PIC 18F4550

Objetivo: Gravar um valor que tem + de 8 Bits na memoria eeprom

Código feito em CCS C Compiler

// COMO GRAVAR UM VALOR QUE TEM + de 8 Bits NA MEMÓRIA EEPROM
#include <18F4550.h>
#device adc = 10        // conversor analogico de 10 bits
# fuses HS, NOWDT, MCLR //clock de alta velocidade, sem hodc time, com reset setado
#use delay(clock = 20MHz)

#define LCD_DB0   PIN_D0
#define LCD_DB1   PIN_D1
#define LCD_DB2   PIN_D2
#define LCD_DB3   PIN_D3
#define LCD_DB4   PIN_D4
#define LCD_DB5   PIN_D5
#define LCD_DB6   PIN_D6
#define LCD_DB7   PIN_D7

#define LCD_E     PIN_E1
#define LCD_RS    PIN_E2

#include <flex_lcd.c>

void main(){
   
   unsigned int16 leitura;
   unsigned int baixo, alto;
   
   lcd_init();
   
   setup_adc( ADC_CLOCK_INTERNAL ); // modulo adc
   setup_adc_ports( AN0 );    // porta apenas AN0
   set_adc_channel( 0 );      // seta com 0
      
   while(true){
      
      leitura = read_adc();   // leitura do canal analógico
      
      if(input(PIN_B0) == 0){
      
         baixo = make8(leitura, 0); // função que pega variavel até 32 bits e separa parte 8 bits, 0 = 8 1° bits
         alto = make8(leitura, 1);   //extrai a parte + significativa de 8 bits
         
         write_eeprom(2, baixo);    // escreve no endereço 2
         delay_ms(10);
      
      }else{
         
         char letra = read_eeprom(0);
         baixo = read_eeprom(1);
         alto = read_eeprom(2);
         
         // 0b 1101 0001 0100 0001
         // 0100 0001 = menos siguinificativa
         // 1101 0001 = mais siguinificativa
         unsigned int16 salvo = make16(alto, baixo); // monta 1 número de 16 bits
         printf(LCD_PUTC, "\fLEITURA: %lu", leitura);
         printf(LCD_PUTC, "\nSALVO: %lu",  salvo);
         delay_ms(100);
      }
   }
}

Saída gerada no PicSimlab


07/03/2023

Efeito máquina de escrever em HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        p{
            font-size: 50px;
            font-family: monospace;
            border-right: 4px solid;
            width: 12ch; /* 12 caracteres */
            white-space: nowrap;    /*para não quebrar a linha*/
            overflow: hidden;   /* esconde os caracteres que ainda não foram digitados*/
            animation: typing 2s steps(12), /* animação de 2 seg, 10 caracteres */
            blinking 0.5s infinite step-end alternate;  /* 0.5 seg de duração */
        }
        @keyframes typing { /* animação 1 */
            from {
                width: 0; /* Começa com largura de 0 */

            }
        }
        @keyframes bliking { /* animação 2*/
            50% {
                border-color: transparent;
            }
        }
    </style>
</head>

<body>
    <p>Olá mundo !</p>
</body>
</html>







06/03/2023

Display LCD 16x4 no Picsimlab

Objetivo: Escrever em todas as linhas do display LCD 16x4 no Picsimlab
Saída gerada no Picsimlab


























Arquivo de biblioteca: flex_lcd.c

/*
   Este código é uma adaptação do flex_lcd.c original obtido no link a seguir:
   https://www.ccsinfo.com/forum/viewtopic.php?t=24661
*/

/*
   A pinagem padrão é a mesma da biblioteca lcd.c 
   que vem com o CCS com os pinos definidos como segue.
   Caso queira utilizar utilizar outros pinos basta definir 
   cada um antes de importar esta biblioteca.
*/

#ifndef LCD_DB4
   #define LCD_DB4   PIN_D4
#endif
#ifndef LCD_DB5
   #define LCD_DB5   PIN_D5
#endif
#ifndef LCD_DB6
   #define LCD_DB6   PIN_D6
#endif
#ifndef LCD_DB7
   #define LCD_DB7   PIN_D7
#endif

#ifndef LCD_DB4
   #define LCD_DB4   PIN_D4
#endif

#ifndef LCD_E
   #define LCD_E   PIN_D0
#endif
#ifndef LCD_RS
   #define LCD_RS   PIN_D1
#endif

/*
   Se queser utilizar apenas 6 pinos com seu LCD,
   basta não declarar a constante LCD_RW.
*/
#ifdef LCD_RW
   #define LCD_RW   PIN_D2
   #define USE_LCD_RW   1
#endif
     

//======================================== 

#define lcd_type 2        // 0=5x7, 1=5x10, 2=2 lines 
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line 


int8 const LCD_INIT_STRING[4] = 
 0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots 
 0xc,                    // Display on 
 1,                      // Clear display 
 6                       // Increment cursor 
 }; 
                              

//------------------------------------- 
void lcd_send_nibble(int8 nibble) 
// Note:  !! converts an integer expression 
// to a boolean (1 or 0). 
 output_bit(LCD_DB4, !!(nibble & 1)); 
 output_bit(LCD_DB5, !!(nibble & 2));  
 output_bit(LCD_DB6, !!(nibble & 4));    
 output_bit(LCD_DB7, !!(nibble & 8));    

 delay_cycles(1); 
 output_high(LCD_E); 
 delay_us(2); 
 output_low(LCD_E); 

//----------------------------------- 
// This sub-routine is only called by lcd_read_byte(). 
// It's not a stand-alone routine.  For example, the 
// R/W signal is set high by lcd_read_byte() before 
// this routine is called.      

#ifdef USE_LCD_RW 
int8 lcd_read_nibble(void) 
int8 retval; 
// Create bit variables so that we can easily set 
// individual bits in the retval variable. 
#bit retval_0 = retval.0 
#bit retval_1 = retval.1 
#bit retval_2 = retval.2 
#bit retval_3 = retval.3 

retval = 0; 
    
output_high(LCD_E); 
delay_cycles(1); 

retval_0 = input(LCD_DB4); 
retval_1 = input(LCD_DB5); 
retval_2 = input(LCD_DB6); 
retval_3 = input(LCD_DB7); 
  
output_low(LCD_E); 
    
return(retval);    
}    
#endif 

//--------------------------------------- 
// Read a byte from the LCD and return it. 

#ifdef USE_LCD_RW 
int8 lcd_read_byte(void) 
int8 low; 
int8 high; 

output_high(LCD_RW); 
delay_cycles(1); 

high = lcd_read_nibble(); 

low = lcd_read_nibble(); 

return( (high<<4) | low); 
#endif 

//---------------------------------------- 
// Send a byte to the LCD. 
void lcd_send_byte(int8 address, int8 n) 
output_low(LCD_RS); 

#ifdef USE_LCD_RW 
while(bit_test(lcd_read_byte(),7)) ; 
#else 
delay_us(60);  
#endif 

if(address) 
   output_high(LCD_RS); 
else 
   output_low(LCD_RS); 
      
 delay_cycles(1); 

#ifdef USE_LCD_RW 
output_low(LCD_RW); 
delay_cycles(1); 
#endif 

output_low(LCD_E); 

lcd_send_nibble(n >> 4); 
lcd_send_nibble(n & 0xf); 

//---------------------------- 
void lcd_init(void) 
int8 i; 

output_low(LCD_RS); 

#ifdef USE_LCD_RW 
output_low(LCD_RW); 
#endif 

output_low(LCD_E); 

delay_ms(15); 

for(i=0 ;i < 3; i++) 
   { 
    lcd_send_nibble(0x03); 
    delay_ms(5); 
   } 

lcd_send_nibble(0x02); 

for(i=0; i < sizeof(LCD_INIT_STRING); i++) 
   { 
    lcd_send_byte(0, LCD_INIT_STRING[i]); 
    
    // If the R/W signal is not used, then 
    // the busy bit can't be polled.  One of 
    // the init commands takes longer than 
    // the hard-coded delay of 60 us, so in 
    // that case, lets just do a 5 ms delay 
    // after all four of them. 
    #ifndef USE_LCD_RW 
    delay_ms(5); 
    #endif 
   } 


//---------------------------- 

void lcd_gotoxy(int8 x, int8 y) 
int8 address; 

if(y != 1) 
   address = lcd_line_two; 
else 
   address=0; 

address += x-1; 
lcd_send_byte(0, 0x80 | address); 

//----------------------------- 
void lcd_putc(char c) 
 switch(c) 
   { 
    case '\f': 
      lcd_send_byte(0,1); 
      delay_ms(2); 
      break; 
    
    case '\n': 
       lcd_gotoxy(1,2); 
       break; 
    
    case '\b': 
       lcd_send_byte(0,0x10); 
       break; 
    
    default: 
       lcd_send_byte(1,c); 
       break; 
   } 

//------------------------------ 
#ifdef USE_LCD_RW 
char lcd_getc(int8 x, int8 y) 
char value; 

lcd_gotoxy(x,y); 

// Wait until busy flag is low. 
while(bit_test(lcd_read_byte(),7));  

output_high(LCD_RS); 
value = lcd_read_byte(); 
output_low(lcd_RS); 

return(value); 
#endif

// Não está funcionando
void lcd_set_cgram_char(unsigned int8 which, unsigned int8 *ptr)
{
   unsigned int i;

   which <<= 3;
   which &= 0x38;

   lcd_send_byte(0, 0x40 | which);  //set cgram address

   for(i=0; i<8; i++)
   {
      lcd_send_byte(1, *ptr++);
   }
  
   #if defined(LCD_EXTENDED_NEWLINE)
    lcd_gotoxy(g_LcdX+1, g_LcdY+1);  //set ddram address
   #endif
}


Arquivo: main.c

#include <16F877A.h>
#use delay(clock = 20MHz)

#define LCD_DB0   PIN_D0
#define LCD_DB1   PIN_D1
#define LCD_DB2   PIN_D2
#define LCD_DB3   PIN_D3
#define LCD_DB4   PIN_D4
#define LCD_DB5   PIN_D5
#define LCD_DB6   PIN_D6
#define LCD_DB7   PIN_D7

#define LCD_E     PIN_E1
#define LCD_RS    PIN_E2

#include <flex_lcd.c>

void main(){

   lcd_init();
   
   while(true){
      
      lcd_gotoxy(1, 1);
      printf(lcd_putc, "LINHA 1");
      
      lcd_gotoxy(1, 2);
      printf(lcd_putc, "LINHA 2");
      
      lcd_gotoxy(17, 1);
      printf(lcd_putc, "LINHA 3");
      
      lcd_gotoxy(17, 2);
      printf(lcd_putc, "LINHA 4");
   }
}

26/02/2023

PWM - Velocidade de ventoinha com PIC 14F4550

Código feito em CCS C Compiler

#include <18F4550.h>
#fuses XT, MCLR, NOWDT
#use delay(clock = 4M)

void main(){
   
   unsigned int16 P, PR2, duty;
   
   PR2 = 124; // inicia com 124 , predefine com freq de 500 Hz
   P = 50; // 50% , percentual desejado
   
   setup_timer_2(T2_DIV_BY_16, PR2, 1); // qual é o prescaler, % desejado, postcaler = 1 para PWM
   setup_ccp1(CCP_PWM);
   
   duty = (unsigned int16)((PR2 + 1) * 4 * (P/100.0));
   set_pwm1_duty(duty); 
   
   while(true){
      
   }
}

Saída gerada no PicSimlab






25/02/2023

Timer 0 com PIC 14F4550

Cálculos:

Crystal = 4 MHz

Clock interno = 4.000.000 / 4 = 1.000.000 Hz

Frequência = Ciclo de máquina = 1 / t
Ciclo de máquina = 1 / 1.000.000 Hz = 1 us

Com 1 timer de 8 bits temos 256 períodos e com o de 16 bits temos 65336 períodos.

Prescaler x períodos  x ciclo de máquina = tempo de interrupção

timer = 8 bits
clock = 4 MHz
prescaler = 1:1

1 . 256 . 1us = 256 us    Ou seja, a cada 256 us à um overflow e consequentemente a interrupção

Para 16 bits e 4 MHz com prescaler 1:16 e pré-carga de 3036

16 . (6536 - 3036) . 1us = 1.000.000 us = 1s


CÓDIGO FEITO EM CCS C Compiler

#include <18F4550.h>
#fuses XT, NOWDT, MCLR
#use delay(clock=4MHz)

#INT_TIMER0
void interrupcao_t0() {
   clear_interrupt(INT_TIMER0);  // limpa os bits de interrupção
   set_timer0(3036);                         // quando chegar em 6536 ele volta em 3036
   output_toggle(PIN_B1);
}

void main () {
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER0);
   
   setup_timer_0(T0_INTERNAL | T0_DIV_16);
   set_timer0(3036);         // o timer vai realizar a pré -carga com 3036 e vai até 6536
   
   while(true) {
      output_toggle(PIN_B0);
      delay_ms(1000);
   }
   
   
}

Saída gerada no PicSimlab



















Palavras chave:

Timer 0 with PIC 14F4550
Тајмер 0 са ПИЦ 14Ф4550
ታይመር 0 ምስ PIC 14F4550
טיימר 0 עם PIC 14F4550
Timer 0 s PIC 14F4550
Timer 0 med PIC 14F4550
Χρονοδιακόπτης 0 με PIC 14F4550
Timer 0 nga adunay Pic 14F4550
Timer 0 Pic 14F4550-тай

24/02/2023

Icones do Bootstrap em HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet"
    href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">

</head>
<body>
     
    <i class="bi bi-envelope-at"></i><br>
    <i class="bi bi-airplane-engines-fill"></i><br>
    <i class="bi bi-bar-chart-fill"></i><br>
    <i class="bi bi-boombox"></i>
    <i class="bi bi-browser-safari"></i>
    <i class="bi bi-buildings"></i>
    <i class="bi bi-chat-dots-fill"></i>
</body>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
</html>

Saída gerada