November 9, 2017

23

Just finished 3 long hours of MicroProcessor. Today’s class was seemingly very simple and easy. Half of our class (including myself) missed our last session due to CAP+ and so I was worried about catching up on 5 whole lessons. However our loving  teacher decided to go easy on us and spent today mostly on the easiest concepts.

#include <mega128.h>
#include <delay.h>

#define TRIGGER PORTD.0

flash unsigned char seg_pat[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
flash unsigned char seg_on[4] = {0x08, 0x04, 0x02, 0x01};

unsigned char echo_st = 0;
unsigned char dsp_no = 0;
unsigned char dist = 0, cnt = 0;
unsigned int N1000, N100, N10, N1;

void Distance_out(void);

void main(void)
{
    DDRB = 0xFF;
    DDRD = 0b11111101;
    DDRG = 0xFF;
    
    PORTB = 0x0;
    PORTD = 0x0;
    TRIGGER = 0;  
    
    TCCR0 = 0b00000111;
    TCNT0 = 176;
    TCCR2 = 0b00000000;
    TCNT2 = 138;
    TIMSK = 0b01000001;
    SREG = 0x80;
                 
    while(1)
    {
        cnt = 0;
        
        TRIGGER = 1;
        delay_us(15);
        TRIGGER = 0;
        
        while(PIND.1 == 0)
        TCCR2 = 138;
        TCNT2 = 0b00000010;
        
        while(PIND.1 != 0)
        {
            if(cnt > 300) break;
        }
        
        TCCR2 = 0b00000000;
        
        if (cnt > 2 && cnt < 300) dist = cnt;
        else dist = 300;
        
        Distance_out();
        delay_ms(100);
    }
}

void Distance_out()
{
    int buf;
    
    N1000 = dist / 1000;
        buf = dist % 1000;
    N100 = buf / 100;
        buf = buf % 100;
    N10 = buf / 10;
    N1 = buf % 10;
    
}

interrupt [TIM0_OVF] void a (void)
{
    unsigned char pat;
    
    TCNT0 = 176;
    if(dsp_no == 0) pat = N1;
    else if (dsp_no == 1) pat = N10;
    else if (dsp_no == 2) pat = N100;
    else pat = N1000;  
    
    PORTG = seg_on[dsp_no];
    PORTB = (seg_pat[pat] & 0x70) | (PORTB & 0x0F);
    PORTD = ((seg_pat[pat] & 0x0F) << 4) | (PORTD & 0x0F);
    dsp_no = (dsp_no + 1) % 4;
}

interrupt [TIM2_OVF] void b (void)
{
    TCNT2 = 138;
    cnt++;
}

▲ Assessment on UltraSound

 

[MOTOR_EX1-2]

#include <mega128.h>

typedef unsigned char u_char;

flash unsigned char seg_pat[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
flash unsigned char seg_on[4] = {0x08, 0x04, 0x02, 0x01};

u_char dsp_no = 0;

u_char pwm = 10;

void ocr3a_set(void);

void main(void)
{
    DDRB = 0xF0;
    DDRD = 0xF0;
    DDRG = 0x0F;
    DDRE = 0b00001000;
    PORTE = 0x0;
    
    EIMSK = 0b00110000;
    EICRB = 0b00001010;
    
    TIMSK = 0b01000000;
    TCCR2 = 0x05;
    TCNT2 = 178;
    
    TCCR3A = 0b10000010;
    TCCR3B = 0x1A;
    TCCR3C = 0x0;
    ICR3H = 0;
    ICR3L = 99;
    
    ocr3a_set();
    SREG = 0x80;
    while(1);
}

interrupt [EXT_INT4] void ext4 (void)
{
    if(pwm < 97) pwm = pwm + 5;
    ocr3a_set();
}

interrupt [EXT_INT5] void ext5 (void)
{
    if(pwm > 3) pwm = pwm - 5;
    ocr3a_set();
}

void ocr3a_set(void)
{
    OCR3AH = 0 ;
    OCR3AL = pwm;
}

interrupt [TIM2_OVF] void timer2_int(void)
{
    u_char dsp_val;
    
    TCNT2 = 178;
    PORTG = seg_on[dsp_no];
    
    if(dsp_no == 0) dsp_val = pwm % 10;
    else if(dsp_no == 1) dsp_val = (pwm % 100) / 10;
    else if(dsp_no == 2) dsp_val = pwm / 100;
    
    PORTD = ((seg_pat[dsp_val] & 0x0F) << 4) | (PORTD & 0x0F);
    PORTB = (seg_pat[dsp_val] & 0x70) | (PORTB & 0x0F);
    
    dsp_no = (dsp_no + 1) % 3;
}


▲ Assessment on Motor

1

11:59 P.M

Advertisements

June 22, 2017

Having a hard time focusing. Final Exams are in two weeks. 

*

We’ve just finished our last three periods of Microprocessor. Just last week we moved on to external interrupts, and I had a hard time getting myself on track. I got a lucky grade of a 100 on today’s evaluation, but I’d really have to spend some more time practicing.

Physics II is such a captivating subject I dearly adore. It’s very attractive – enchanting, almost, all the theories and the beauty of the finest equations.

Acing Calculus. Grueling, but I guess it’s rewarding enough.

*

Feeling so blue and gray and pale and dark. Definitely the exams are stressing me out. There should be a word to coin this tiresome distress. Something like examinautiousness could work. Sounds disgusting enough.

 

04:07 PM