336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>
#include <stdlib.h>

#define enable                5
#define registerselection  6

void send_a_command(unsigned char command);        //명령어전송 메소드
void send_a_character(unsigned char character);         //글자전송 메소드
void send_a_string(char *string_of_characters);            //문자열전송 메소드

int main(void)
{
    DDRA = 0xFF;                                        //LCD의 D0~D7까지 (Output)
    DDRB = 0b11111111;                              //(Output)
    PORTB|=(1<<PINB0)|(1<<PINB1);            //PORTB레지스터의 PINB0, PIN1포트를 Set
    DDRD = 0b11111110;                              //D0는 RS232포트신호를 위한 입력.
    _delay_ms(50);
    
    UCSRB |=(1<<RXEN)|(1<<RXCIE);        //UCSRB레지스터의 RXEN, RXCIE를 Set
    UCSRC |=(1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);
    UCSRC &=~(1<<UMSEL);            //Setting UMSEL to 0 for asyncronous ()
    UBRRH &=~(1<<URSEL);            //UBRRH레지스터의 URSEL을 0으로 리셋
    UBRRL=6;
    
    char ADMIT [5][4]={{(0x97),(0xa1),(0x90),(0x92)},

{(0x97),(0xa1),(0x90),(0x93)},

{(0x97),(0xa1),(0x90),(0x94)},

{(0x97),(0xa1),(0x90),(0x95)},

{(0x97),(0xa1),(0x90),(0x96)}};            //5Row, 4Column
    

    int16_t COUNTA = 0;                                //Short
    char SHOWA [4];
    int i=0;

    send_a_command(0x01);                         //Clear Screen 0x01 = 00000001
    _delay_ms(50);
    send_a_command(0x38);
    _delay_ms(50);
    send_a_command(0b00001111);
    _delay_ms(50);
    char MEM[4];
    send_a_string ("RFID NUMBER");
    send_a_command(0x80 + 0x40 + 0);
    

   while(1)
    {
        while(!(UCSRA&(1<<RXC)));
        {
            
        }
        COUNTA=UDR;
        MEM[0]=COUNTA;
        itoa(COUNTA,SHOWA,16);
        send_a_string(SHOWA);
        
        while(!(UCSRA&(1<<RXC)));
        {
            
        }
        COUNTA=UDR;
        itoa(COUNTA,SHOWA,16);
        send_a_string(SHOWA);
        MEM[1]=COUNTA;
        
        while(!(UCSRA&(1<<RXC)));
        {
            
        }
        COUNTA=UDR;
        itoa(COUNTA,SHOWA,16);
        send_a_string(SHOWA);
        MEM[2]=COUNTA;
        while(!(UCSRA&(1<<RXC)));
        {
            
        }
        COUNTA=UDR;
        itoa(COUNTA,SHOWA,16);
        send_a_string(SHOWA);
        MEM[3]=COUNTA;
        
        send_a_string("        ");

        
        send_a_command(0x80 + 0x40 + 0);
        
        UCSRB &=~(1<<RXEN);
        for (i=0;i<5;i++)
        {
            
                if ((MEM[0]==ADMIT[i][0])&(MEM[1]==ADMIT[i][1])&(MEM[2]==ADMIT[i][2])&(MEM[3]==ADMIT[i][3]))
                {
                    PORTB|=(1<<PINB3);
                    PORTB&=~(1<<PINB0);
                    _delay_ms(220);
                    _delay_ms(220);
                    _delay_ms(220);
                    _delay_ms(220);
                    _delay_ms(220);
                    _delay_ms(220);
                    PORTB|=(1<<PINB0);
                    PORTB&=~(1<<PINB1);
                    _delay_ms(220);
                    _delay_ms(220);
                    _delay_ms(220);
                    _delay_ms(220);
                    _delay_ms(220);
                    _delay_ms(220);
                    PORTB&=~(1<<PINB3);
                    PORTB|=(1<<PINB1);
                }
        }
        UCSRB |=(1<<RXEN);
    }
}

//▼메소드 선언들

void send_a_command(unsigned char command)    //void 메소드명(변수)
{
    PORTA = command;
    PORTD &= ~ (1<<registerselection);
    PORTD |= 1<<enable;
    _delay_ms(20);
    PORTD &= ~1<<enable;
    PORTA = 0;
}

void send_a_character(unsigned char character)
{
    PORTA = character;
    PORTD |= 1<<registerselection;
    PORTD |= 1<<enable;
    _delay_ms(20);
    PORTD &= ~1<<enable;
    PORTA = 0;
}
void send_a_string(char *string_of_characters)
{
    while(*string_of_characters > 0)
    {
        send_a_character(*string_of_characters++);
    }
}


Posted by ElectricShock
:
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


Naver
[HP33120a] :: HP사의 함수발생기 모델명 (Trigger Input이 있는게 특징이다.)



Drawing Lissajous Curves on a Oscilloscope


Lissajous curves () are two dimensional figures where the points (x,y) are defined by sine functions with different coefficients:

잠시 리자주 커브의 어원을 살펴보자면 아래와 같다.

서로 수직 방향으로 진동하는 단진동을 합성하였을 때,

그 궤도가 그리는 도형. 두 개의 진동수의 비가 유리수라면 닫힌 도형이 됨. 

프랑스의 물리학자 리사주(J. A. Lissajous)가 발견하였음. 

리사주 도형.

x = sin(t)                       //pitch가 1, phase 0.

y = sin(at+b)                //위아래로 pitcha만큼 늘어났고, 좌우로 phaseb만큼 shift했다.

By modifying a and b over the period t, 

a wide variety of fascinating curves 

can be drawn, some of which look almost 3D!

조절함으로써 a와 b를 over 주기 t너머로,

a 넓은 변수들.. of 매혹적인 커브들의

..은can be 그려질수있다, some of which 보이는 거의 3D!

For example, 

if y is a sine wave that is exactly 90 degrees offset (“out of phase”) from x, the plot is a perfect circle:

(out of phase에 대한 설명 ☞)

예컨데,

만약 y가 sine 웨이브라면 that is 정확히 90도 오프셋인 from x로부터,

the plot은 완벽한 원이된다:


x = sin(t)

y = sin(t+pi/2)        //pitch는 그대로 1, phase가 오른쪽으로 π/2 만큼 shift

-------------------------------------------------------------------------------------

In the lab, 

an oscilloscope is the ideal instrument for plotting x and y coordinates. Typically, an oscilloscope will plot the voltage of an primary input 

on the y axis 

vs. time on the x- axis.

실험에서,

an Oscilloscope는 the 이상적 장비이다. for 그래프화하는 x와 y 좌표를.

전형적으로, an Oscilloscope는 will 그릴것이다. the 전압을 of an 초기입력의

on the Y축상에 

반면 시간은(그릴것이다.) on the X축상에

----------------------------------------------------------------------------------------

However, 

most oscilloscope will allow you to supply an external input 

that will allow you to directly control the x axis.

We can connect a function generator to both the x and y axis 

and begin to draw Lissajous patterns.

헌데, 

대부분의 Oscilloscope는 will 허락할것이다. 네가 to공급하는걸an외부입력을

that will 허락할 네가 to 직접적으로 제어하는걸 the x축을.

우린 can 연결할 수 있다. a 함수발생기를 to 두 XY축에

and 시작할수있다. to 그리는걸 Lissajous Patterns를.

----------------------------------------------------------------------------------------

By shifting the frequency and phase of the signals, you can get different shapes. 

However, even at the office we don’t yet have two (working) function generators which can be phase locked. 

In the picture above, you can see that we’re using a HP33120A and a HP 200AB. 

The 33120A has a trigger input, but no such luck for the old-school 200AB. With some fiddling, they can be brought into phase, but it’s much easier and more fun to build our own frequency generators. That’s where the DAC Shields and an Arduino come in.

---------------------------------------------------------------------------------------

The DAC Shield has inputs for positive and negative power and an output for the signal. For this exercise, we’ll be using two bench power supplies (Mastech HYB3003 and Mastech HYB3003), but you could also use two batteries.

----------------------------------------------------------------------------------------

The output of one shield is connected to the X-axis input of the ‘scope the other is connected to the Y-axis. On the Tektronix 2246 shown here, channel 1 can be set to drive the X-axis.
The trick to initially plotting a circle is to make sure that the amplitude of both axis move the cursor equal amounts, so make sure to set both “volts/div” settings the same.

-----------------------------------------------------------------------------------------

To start with a circle we simply write a program that generates a sine wave at a given frequency on channel 1 and then creates a second sine wave on channel two which is 90 degrees out of phase.

while(true):
write(channel1, sin(t));
write(channel2 sin(t+pi/2))

While this pseudo code is close, some considerations have to be made due to the discrete nature of the DAC. For instance, the resolution of the DAC will determine the value of the minimum output, zero and the maximum output. In this case we have a 12bit DAC with positive and negative supply rails at 10 V and -10V, respectively. Writing a “0″ to the DAC will result in an output of -10V. Similarly, writing “2048″ will output 0V and “4096″ will output 10V.

Thus, we need to scale our original pseudo equations:

write (channel1, (sin(t) * 2048 + 2047))

Where t = 0 would be 2047, t=pi/2 is 4096 and ….

Another consideration is the base frequency for the sine wave; this will depend on how fast you can write to the DAC and how many cycles it takes to compute the sine wave. Inserting different delays between samples of the wave generates different frequencies. For example if you the second channel is doubled in frequency from the first you will generate the following shape.

-----------------------------------------------------------------------------------

Also by increasing the phase of one the the sine wave though every iteration of the loop the figure can be animated as seen here on a Rigol MSO4050 in which we are evaluating.

Example source code and schematic for the DAC shield can be found on Github here, Also the Power DAC Shield can be purchased from Tindie.

Posted by ElectricShock
:
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

원래 영문자료여서 한글과 영문이 섞여있음을 이해해주세요



Baudrate = Bit per Second

Fosc = System Clock Frequency (초기치는 1MHz이다. External Oscillator를 의미하기도 한다.)

UBBR = Contents of UBRRL and UBRRH Registers.  (UBRRL과 UBRRH 레지스터의 내용물이다.)

========================================================================================

Coding 시, Initializing UART가 중요하다. 단계는 아래와 같다.

1.Setting하기 BaudRate를.

2.Setting하기 Data Size를.

3.활성화시키기 Rx, Tx를 (UCSRB의 TXEN과 RXEN를 1로 Set시킨다.)

4.Setting하기 Parity비트와 Stop비트들을.

1
2
3
4
5
6
7
8
9
10
11
12
// define some macros
#define BAUD 9600                         // define baud
#define BAUDRATE ((F_CPU)/(BAUD*16UL)-1)  // set baud rate value for UBRR
  
// function to initialize UART
void uart_init (void)
{
    UBRRH = (BAUDRATE>>8);                      
// shift the register right by 8 bits
    UBRRL = BAUDRATE;                           
// set baud rate
    UCSRB|= (1<<TXEN)|(1<<RXEN);                // enable receiver and transmitter
    UCSRC|= (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);   // 8bit data format
}

Explanation(=설명)

보드레이트를 세팅하기위해 사용된 변수는 BAUD이다.

BAUDRATE는 정의된다. as per 계산식에 따라.

(as per : 비율, 가격, 측청값, 특정 체계, 계획 등을 언급할 때 사용)

(according to : 사람, 서적, 문서, 등을 언급할 때 사용)


한가지 기억해야할건 that UCSRCUBRRH는 공유한다. 같은 I/O 위치를.

그래서 selection/switching 을 제어하는 bit는 URSEL bit이다. in the UCSRC 레지스터안의.

이건 만은 혼동을 야기한다.

만약 이 비트가 올바르게 다뤄지지 않는다면, UART는 동작하지않는다.


만약 URSEL이 Zero이면 during a Write Operation동안에,

the UBRRH값은 will be 업데이트 될것이다.

만약 URSEL이 One이면,

the UCSRC 세팅이 will be 업데이트 될것이다.

이건 의미한다. URSEL 비트가 0이면, even if 우리가 addressing(=교신선택)할지라도 UCSRC를

UBRRH는 will be addressed될것이다.

=========================================================================================




BaudRate를 계산할때 표를 사용하면 편하다. (왼쪽 아이콘을 클릭)

UBRR = UBRRH * 256 + UBRRL;



Posted by ElectricShock
:

BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
MiDi (2)
Programming(=프로그래밍) (3)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백