Haberler:

Foruma Resim Yükleme ve Boyut Sınırlaması ( ! )  https://bit.ly/2GMFb8H

Ana Menü

C sorularım

Başlatan xoom, 08 Ekim 2024, 19:42:35

mehmet

#15
1ms yeterli olmaz. 20us ila başlayın.

Deneme amaçlı; 14(16) byte bir tablo oluşturun. 7 segmentlerde olduğu gibi. Bu nasıl duracak bakın.
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr
https://creativecommons.org/licenses/by/4.0/deed.tr "CC BY"

RaMu

HC4094write() fonksiyonunda 4094 ün latch özelliğini kullanmanız lazım.
Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html

xoom

#17
Alıntı yapılan: RaMu - Dün, 09:07:11HC4094write() fonksiyonunda 4094 ün latch özelliğini kullanmanız lazım.
void HC4094write()
{
    for(int i=0; i<16; i++)
    {
        if(currentVal & (1<<i))
        {
            HAL_GPIO_WritePin(SER_PORT, SER_PIN, GPIO_PIN_SET);
        }
        else
        {
            HAL_GPIO_WritePin(SER_PORT, SER_PIN, GPIO_PIN_RESET);
        }
        HAL_GPIO_WritePin(SRCLK_PORT, SRCLK_PIN, GPIO_PIN_RESET);
        HAL_GPIO_WritePin(SRCLK_PORT, SRCLK_PIN, GPIO_PIN_SET);
    }
    HAL_GPIO_WritePin(RCLK_PORT, RCLK_PIN, GPIO_PIN_RESET);
    HAL_GPIO_WritePin(RCLK_PORT, RCLK_PIN, GPIO_PIN_SET);
}
RCLK pini ile LATCH özelliğinden bahsetmiyor musunuz?

xoom

Alıntı yapılan: mehmet - 21 Ekim 2024, 18:33:541ms yeterli olmaz. 20us ila başlayın.

Deneme amaçlı; 14(16) byte bir tablo oluşturun. 7 segmentlerde olduğu gibi. Bu nasıl duracak bakın.
for(int i=0;i<14;i++)
        {
            currentVal=Status[i];
            HC4094write();
            HAL_Delay(1);
            currentVal=0;
            HC4094write();
        }

bu tarama blogunu timer içinde kullanınca 1ms geçikme sanırım olmamalı ama nasıl?

mehmet

12F675 ile simülasyonda kısmen çalışıyor, ilk biti yutuyor. Elimde 4094 olmadığı için deneyemiyorum. Bir ara 595 ile deneyeceğim.

/*
 * File:   main.c
 * Author: mehmet
 *
 * Created on 22 Ekim 2024 Salı, 13:20
 * 
 */

// PIC12F675 Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/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 = OFF      // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = ON       // Brown-out Detect Enable bit (BOD enabled)
#pragma config CP = ON          // Code Protection bit (Program Memory code protection is enabled)
#pragma config CPD = ON         // Data Code Protection bit (Data memory code protection is enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <stdint.h>

#define _XTAL_FREQ              4000000

#define _BV(bt)                 (1u << (bt))
#define sbi(port, bt)           (port) |= _BV(bt)    /* Set bit number n in byte b   */
#define cbi(port, bt)           (port) &= ~_BV(bt)   /* Clear bit number n in byte b */

#define rbi(port, bt)           (port) & _BV(bt)     /* Read bit number n in byte b  */
#define fbi(port, bt)           (port) ^= _BV(bt)    /* Flip bit number n in byte b  */
#define bit_is_set(port, bt)    (port) & _BV(bt)     /* Test if bit number n in byte b is set   */
#define bit_is_clear(port, bt)  (!port) & _BV(bt)   /* Test if bit number n in byte b is clear */

#define CLOCK                   GPIObits.GP1
#define LATCH                   GPIObits.GP2
#define DATA                    GPIObits.GP0

#define CLOCK_DIR               TRISIObits.TRISIO1
#define LATCH_DIR               TRISIObits.TRISIO2
#define DATA_DIR                TRISIObits.TRISIO0

uint16_t sayac = 0;

const uint8_t tablo[(5 * 3 * 2) + 2] = {
    //76543210    76543210
    0b11111111, 0b11111111, //boş
    0b11111110, 0b00000001, // LED1
    0b11111101, 0b00000001, // LED2
    0b11111011, 0b00000001, // LED3

    0b11111110, 0b00000010, // LED4
    0b11111101, 0b00000010, // LED5
    0b11111011, 0b00000010, // LED6

    0b11111110, 0b00000100, // LED7
    0b11111101, 0b00000100, // LED8
    0b11111011, 0b00000100, // LED9

    0b11111110, 0b00001000, // LED10
    0b11111101, 0b00001000, // LED11
    0b11111011, 0b00001000, // LED12

    0b11111110, 0b00010000, // LED13
    0b11111101, 0b00010000, // LED14
    0b11111011, 0b00010000 // LED15
};

/*
 * 
 */
void spi_wr8(uint8_t val) // write a byte to software SPI
{
    for(uint8_t i = 8; i; i--)
    {
        CLOCK = 0;
        DATA = 0;
        if(val & 0x80) // MSB first
            DATA = 1;
        val <<= 1;
        CLOCK = 1;
    }
}

/*
 * Test için yazıldı.
 */
void hc4094Yaz(uint8_t sayi)
{
    uint8_t k;
    k = sayi;

    LATCH = 0b0;
    spi_wr8(tablo[(k * 2u)]);
    spi_wr8(tablo[(k * 2u) + 1u]);
    LATCH = 0b1;
}

/*
 * http://eng-serve.com/pic/pic_timer.html
 */
void kesmeHazirla(void)
{
    //    //Timer0 Registers Prescaler= 1 - TMR0 Preset = 156 - Freq = 10000.00 Hz - Period = 0.000100 seconds
    //    OPTION_REGbits.T0CS = 0; // bit 5  TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
    //    OPTION_REGbits.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
    //    OPTION_REGbits.PSA = 1; // bit 3  Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
    //    OPTION_REGbits.PS2 = 0; // bits 2-0  PS2:PS0: Prescaler Rate Select bits
    //    OPTION_REGbits.PS1 = 0;
    //    OPTION_REGbits.PS0 = 0;
    //    TMR0 = 56; // preset for timer register (56->5KHz,156->10KHz, 206->20KHz)

    //Timer0 Registers Prescaler= 1 - TMR0 Preset = 156 - Freq = 10000.00 Hz - Period = 0.000100 seconds
    OPTION_REGbits.T0CS = 0; // bit 5  TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
    OPTION_REGbits.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
    OPTION_REGbits.PSA = 0; // bit 3  Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
    OPTION_REGbits.PS2 = 0; // bits 2-0  PS2:PS0: Prescaler Rate Select bits
    OPTION_REGbits.PS1 = 0;
    OPTION_REGbits.PS0 = 1;
    TMR0 = 6; // preset for timer register (6->1KHz)

    // Interrupt Registers
    INTCON = 0; // clear the interrpt control register
    INTCONbits.TMR0IE = 1; // bit5 TMR0 Overflow Interrupt Enable bit...1 = Enables the TMR0 interrupt
    INTCONbits.TMR0IF = 0; // bit2 clear timer 0 interrupt flag
    INTCONbits.GIE = 1; // bit7 global interrupt enable
}

/*
 * 
 */
void mcuInit(void)
{
    OPTION_REG = 0b00000000;
    CMCON = 0b00000111;
    VRCON = 0b00000000;
    WPU = 0b00000111; 
    IOCB = 0;

    GPIO = 0x00;

    DATA_DIR = 0b0;
    CLOCK_DIR = 0b0;
    LATCH_DIR = 0b0;
}

/*
 * 
 */
void main(void)
{
    mcuInit();
    kesmeHazirla();

    sayac = 63;
    
    while(1)
    {            
        
    }
}

/*
 * 
 */
void interrupt ISR(void)
{
    static uint8_t h = 0;
    uint8_t k = 0;
    
    if(INTCONbits.TMR0IF == 1) 
    {
        k = 0;
        if(bit_is_set(sayac, h))
        {
            k = h;
        }

        LATCH = 0b0;        
        spi_wr8(tablo[(k * 2u)]);        
        spi_wr8(tablo[(k * 2u) + 1u]);        
        LATCH = 0b1;       

        if(h++ > 15) h = 0;

        INTCONbits.TMR0IF = 0;
        INTCONbits.TMR0IE = 1;
        TMR0 = 6;
    }
}
////////////////////////////////////////////////////////////////////////////////
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr
https://creativecommons.org/licenses/by/4.0/deed.tr "CC BY"