Sunuyu indir
Sunum yükleniyor. Lütfen bekleyiniz
YayınlayanBercu Çevik Değiştirilmiş 6 yıl önce
1
Microprocessors and Programming Department of Mechatronics Engineering
Lecture 1 1 Microprocessors and Programming Dr. Kadir ERKAN Department of Mechatronics Engineering Fall : 2017 9/11/2018
2
9/11/2018
3
9/11/2018
4
9/11/2018
5
9/11/2018
6
Synchronous communication
When using the synchronous communication – the information is transmitted from the transmitter to the receiver: in sequence bit after bit with fixed baud rate and the clock frequency is transmitted along with the bits That means that the transmitter and the receiver are synchronized between them by the same clock frequency. The clock frequency can be transmitted along with the information, while it is encoded in the information itself, or in many cases there is an additional wire for the clock. This type of communication is faster compare to the asynchronous communication since it is "constantly transmitting” the information, with no stops. 9/11/2018
7
Asynchronous communication
When using the asynchronous communication - the transmitter and the receiver refraining to transmit long sequences of bits because there isn't a full synchronization between the transmitter, that sends the data, and the receiver, that receives the data. In this case, the information is divided into frames, in the size of byte. Each one of the frame has: “Start” bit marks the beginning of a new frame. “Stop” bit marks the end of the frame. Frames of information must not necessarily be transmitted at equal time space, since they are independent of the clock. 9/11/2018
8
9/11/2018
9
9/11/2018
10
9/11/2018
11
9/11/2018
12
9/11/2018
13
9/11/2018
14
"Bir şeyin ters gitme olasılığı varsa, ters gidecektir."
Murphy Kanunları , Amerikalı mühendis Edward A. Murphy, jr. tarafından, başarısızlıklar ve hata kaynaklarının karmaşık sistemlerde incelenmesi üzerine ortaya konan özdeyişlerdir. "Bir şeyin ters gitme olasılığı varsa, ters gidecektir." "Bir şeyin birkaç şekilde ters gitme olasılığı varsa, hep en kötü sonuç doğuracak şekilde ters gidecektir." "Bir şeyin ters gidebileceği olasılıkları engelleseniz bile, anında yeni bir olasılık ortaya çıkacaktır." "Bir şeyin olma olasılığı, isteme olasılığı ile ters orantılıdır." "Er ya da geç olası en kötü koşullar zincirlemesi vuku bulacaktır." "Ne zaman bir şeyden vazgeçseniz, vazgeçtiğiniz o şey size geri gelir." "Olmuyorsa zorlayın, kırılırsa zaten değişmesi gerekirdi." "Ne kadar beklersen bekle istenmediği zaman gelecektir." "Çözülen her problem yeni problemler yaratır." "Her şey yolunda gidiyorsa, kesin bir terslik vardır." 9/11/2018
15
9/11/2018
16
9/11/2018
17
9/11/2018
18
9/11/2018
19
9/11/2018
20
9/11/2018
21
9/11/2018
22
USART in PIC The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is one of the two serial I/O modules. (USART is also known as a Serial Communications Interface or SCI.) The USART can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as CRT terminals and personal computers, or it can be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as A/D or D/A integrated circuits, serial EEPROMs, etc. The USART can be configured in the following modes: • Asynchronous (full-duplex) • Synchronous – Master (half-duplex) • Synchronous – Slave (half-duplex) 9/11/2018
23
9/11/2018
24
9/11/2018
25
TXSTA: TRANSMIT STATUS AND CONTROL REGISTER (ADDRESS 98h)
9/11/2018
26
RCSTA: RECEIVE STATUS AND CONTROL REGISTER (ADDRESS 18h)
9/11/2018
27
interrupts #USE RS232(constant1, constant2,…)
This directive tells the compiler the baud rate and pins used for serial I/O. This directive takes effect until another RS232 directive is encountered. The #USE DELAY directive must appear before this directive can be used. This directive enables use of built-in functions such as GETC, PUTC, and PRINTF. The functions created with this directive are exported when using multiple compilation units. To access the correct function use the stream identifier. When using parts with built-in SCI and the SCI pins are specified, the SCI will be used. If a baud rate cannot be achieved within 3% of the desired value using the current clock rate, an error will be generated. #INT_RDA RS232 receive data available #INT_TBE RS232 transmit buffer empty interrupts 9/11/2018
28
#USE RS232 9/11/2018
29
set_uart_speed( ) Changes the baud rate of the built-in hardware RS232 serial port at run-time. This function is only available on devices with a built in UART. set_uart_speed (baud, [stream, clock]) baud is a constant representing the number of bits per second. stream is an optional stream identifier. clock is an optional parameter to indicate what the current clock is if it is different from the #use delay value // Set baud rate based on setting of pins B0 and B1 switch( input_b() & 3 ) { case 0 : set_uart_speed(2400); break; case 1 : set_uart_speed(4800); break; case 2 : set_uart_speed(9600); break; case 3 : set_uart_speed(19200); break; } 9/11/2018
30
RS232 Serial Port Functions
9/11/2018
31
Example Code 9/11/2018
32
Example Code /******************************************************
RS232 Serial Communication Sample *******************************************************/ #include <16f877.h> #fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD #use delay (clock= ) #define use_portb_lcd TRUE #include <lcd.c> #use rs232 (baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, stop=1) char klavye[80]; #int_rda void serihaberlesme_kesmesi () { disable_interrupts(int_rda); output_high(pin_c5); gets(klavye); printf("\n\rYazdiginiz Metin> %s\n",klavye); printf(lcd_putc,"\f%s",klavye); output_low(pin_c5); printf("\n\rKlavyeden bir metin giriniz ve enter tusuna basiniz>"); } 9/11/2018
33
Example Code void main ( ) { setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED); … output_low(pin_c5); lcd_init(); printf("\r**************** Merhaba *********************"); printf("\n\rKlavyeden girdiginiz bilgiler LCD'de gorunecektir\n\n"); printf("\n\rKlavyeden bir metin giriniz ve enter tusuna basiniz>"); enable_interrupts(GLOBAL); while(1) enable_interrupts(int_rda); } 9/11/2018
34
Parallel Slave Port The parallel slave port on the PIC16F877 chip is designed to allow parallel communications with an external 8-bit system data bus or peripheral. Port D provides the 8 I/O data pins, and Port E three control lines: Read, Write, and Chip Select. If data are to be input to the port, the pin data direction is set accordingly and data presented to Port D. The chip select input must be set low and the data latched into the port data register by taking the write line low. Conversely, data can be read from the port using the read line. Either operation can initiate an interrupt. 9/11/2018
35
Parallel Slave Port Registers
9/11/2018
36
Parallel Slave Port Pin Structure
9/11/2018
37
9/11/2018
38
setup_psp(mod) Configures various options in the PMP/EPMP module. The options are present in the device.h file and they are used to setup the module. The PMP/EPMP module is highly configurable and this function allows users to setup configurations like the Slave mode, Interrupt options, address increment/decrement options, Address enable bits and various strobe and delay options. MOD: PSP_ENABLED PSP_DISABLED 9/11/2018
39
PSP_INPUT_FULL(), PSP_OUTPUT_FULL(), PSP_OVERFLOW()
9/11/2018
40
Example Code 9/11/2018
41
Example Code /******************************************************
PSP Application *******************************************************/ #include <16f877A.h> #fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD #use delay (clock= ) void main ( ) { setup_timer_1(T1_DISABLED); // T1 zamanlayıcısı devre dışı setup_timer_2(T2_DISABLED,0,1); // T2 zamanlayıcısı devre dışı … setup_psp(PSP_ENABLED); while (1) { output_b(PSP_DATA); } 9/11/2018
42
Example Code 9/11/2018
43
Example Code 9/11/2018
Benzer bir sunumlar
© 2024 SlidePlayer.biz.tr Inc.
All rights reserved.