Advertisement
Electgpl

8051 - Envio Entero UART Silabs

Sep 28th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include<reg51.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. // function prototypes
  5. void delay(unsigned int ms);
  6. void putc1( chr);
  7. void windspeed_read( void);
  8. void initialize(void);
  9. void record_wind(unsigned char counter);
  10. void puts1(char* p);
  11. sbit P3_2 = P3^2;
  12. sbit P3_3 = P3^3;
  13. // global variables declared
  14. unsigned char c = 0;
  15. char *ptr;
  16. int i;
  17. char buf[16];
  18. char *p;
  19. // delay function to create a delay of 1 sec
  20. void delay(const unsigned int ms){
  21.    unsigned int x;
  22.    unsigned int y;
  23.    for(x=0;x<ms;x++){
  24.       for(y=0;y<=113;y++);
  25.    }
  26. }
  27. // to print the character in UART and serial window
  28. void putc1(c){
  29.    SBUF=c;
  30.    while(TI==0);            //Wait until the character is completely sent
  31.    TI=0;                    //Reset the flag
  32. }
  33. // main function
  34. void main(){
  35.    IE=0x81;
  36.    EX0=1;
  37.    EA=1;
  38.    while(1){
  39.    }
  40. }
  41. void initialize(){
  42.    SCON=0x50;               //SCON: mode 1, 8-bit UART, enable receive
  43.    TMOD|=0x20;              //TMOD: timer 1, mode 2, 8-bit
  44.    TH1=0xFD;                //TH1:  for 9600 baud
  45.    TR1=1;                   //TR1:  timer 1 run
  46. }
  47. void windspeed_read(void) interrupt 0 {
  48.    c++;
  49.    sprintf(buf,"%d",c);
  50.    p=buf;
  51.    while(*p){
  52.       P2=*p;
  53.       putc1(*p++);
  54.    }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement