Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1.  
  2.    
  3.      
  4. #include "MKL46Z4.h"                    // Biblioteka wykorzystywanej plytki.
  5. //#include "lcd.h"                          // Biblioteka obslogi wyswietlacza lcd.
  6.  
  7.  
  8. //#define UART0_Rx 0  //Rx is first in table
  9. //#define UART0_Tx 1  //Tx is second in table
  10.  
  11.  
  12. void init_UART(void){
  13.    
  14.     SIM->SCGC4 |= SIM_SCGC4_UART2_MASK;     // Odblokowanie zegara dla UART2.      /* Enable Clock to UART2*/
  15.     SIM->SCGC5 |= SIM_SCGC5_PORTE_MASK;     // Odblokowanie zegara dla portu E.         /* Enable Clock to PORTA*/
  16.     PORTE->PCR[16] |= PORT_PCR_MUX(3UL);  /* Pin PTA1 is alt2 (UART)*/
  17.     PORTE->PCR[17] |= PORT_PCR_MUX(3UL);  /* Pin PTA2 is alt2 (UART) */
  18.    
  19.     UART2->C2 &=~ UART_C2_TE_MASK;        // /* disable transmitting*/
  20.     UART2->C2 &=~ UART_C2_RE_MASK;   /* disable receiving */
  21.  
  22.     UART2->BDH |= UART_BDH_SBR(0x156);      /*set value of SBR to BDH (it is the first divider)0x01*/
  23.     UART2->BDL |= UART_BDL_SBR(0x156);      /*set value of SBR to BDL */
  24.     UART2->BDH &=~ UART_BDH_SBNS_MASK;   /*set value of  SBNS (0 - one bit, 1- two bits) 0x38*/
  25.    
  26.     UART2->C1 &=~ UART_C1_M_MASK;                   // 8 bitow danych.          /* M selects between 8 and 9 bits data MODE*/
  27.     UART2->C1 &=~ UART_C1_PE_MASK;              // Brak bitu parzystosci.       /* PE - parity enable (0 - no hardware parity)*/
  28.    
  29.    
  30.    
  31.     UART2->C2 |= UART_C2_TE_MASK;   /* enable transmitting*/
  32.     UART2->C2 |= UART_C2_RE_MASK;   /* enable receiving */
  33.    
  34. }
  35.  
  36.  
  37.  
  38. int main (void) {
  39.     uint8_t data = 255;
  40.     init_UART();
  41.     //init_LCD();                                   // Inicjalizacja wyswietlacza lcd.
  42.     for(;;) {
  43.         //set_float_LCD(3.789,3);
  44.         //while( (UART0->S1 & 0x80) != 0) {
  45.         UART2->D='a';
  46.         //}
  47.         //while( (UART0->S1 & 0x80) != 0);
  48.         delay(1000);
  49.         //set_float_LCD(1.121,3);
  50.         delay(1000);
  51.         //delay(1000);
  52.         //delay(1000);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement