日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

使用Keil语言的嵌入式C编程教程(下)

發布時間:2023/11/28 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Keil语言的嵌入式C编程教程(下) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用Keil語言的嵌入式C編程教程(下)

用8051單片機進行定時器/計數器的計算與編程

延遲是應用軟件開發中的重要因素之一。然而,在實現定時延遲的過程中,正常的延遲并不能給出克服這一問題的寶貴結果。定時器和計數器是微控制器的硬件組成部分,在許多應用中使用它來提供具有計數的寶貴時間延遲脈沖兩個任務都是通過軟件技術實現的。

定時器延遲

WAP使用T1M2(timer1和mode2)生成500us延時?

#include<reg51.h>

void main()

{

unsigned char i;

TMOD=0x20; //set the timer mode//

for(i=0i<2;i++) //double the time daly//

{

TL1=0x19; //set the time delay//

TH1=0x00;

TR1=1; //timer oN//

While(TF1==0); //check the flag bit//

TF1=0;

}

TR1=0; //timer off//

}

Normal Loop Delay

void delay()

{

unsignedint k;

for(k=0;k<30000;k++);

}

基于8051單片機的串行通信計算與編程

串行通信通常用于發送和接收信號。8051微控制器包括由Rx和Tx引腳發送和接收的信號的UART串行通信。UART接收字節的數據并按順序發送各個位。寄存器是一種在存儲器中收集和存儲數據的方法。UART是一種半雙工協議。半雙工是指傳輸和接收數據,但不能同時進行。

  1. WAP將字符“S”傳輸到串行窗口使用9600作為波特率?

28800是8051微控制器的最大波特率

28800/9600= 3

That baud rate ‘3’ is stored in the timers

#include<reg51.h>

void main()

{

SCON=0x50; //start the serial communication//

TNOD=0x20; //selected the timer mode//

TH1=3; // load the baud rate//

TR1=1; //Timer ON//

SBUF=’S’; //store the character in the register//

while(TI==0); //check the interrupt register//

TI=0;

TR1=0; //OFF the timer//

while(1); //continuous loop//

}

  1. WAP從超級終端接收數據并使用9600波特將數據發送到微控制器的端口0?
  2. 28800是8051微控制器的最大波特率

28800/9600=3

That baud rate ‘3’ is stored in the timers

#include<reg51.h>

void main()

{

SCON=0x50; //start the serial communication//

TMOD=0x20; //selected the timer mode//

TH1=3; // load the baud rate//

TR1=1; //Timer ON//

PORT0=SBUF; //send the data from SBUF to port0//

while(RI==0); //check the interrupt register//

RI=0;

TR1=0; //OFF the timer//

while(1); //stop the program when character is received//

}

用8051單片機中斷程序

中斷是強制停止當前程序并立即執行其他程序的信號。8051微控制器提供6個內部和外部中斷源。當中斷發生時,微控制器暫停當前任務并通過執行ISR處理中斷,然后微控制器返回到最近的任務。

WAP在定時器0中斷時執行左移操作,然后在主功能中執行P0的中斷操作?

#include<reg51.h>

unsigned char b;

void timer0() interrupt 2 //selected timer0 interrupt//

{

b=0x10;

P1=b<<2;

}

void main()

{

unsigned char a,i;

IE=0x82 //enable the timer0 interrupt//

TMOD=0x01;

TLo=0xFC; //interrupt timer//

TH1=0xFB;

TR0=1;

a=0x00;

while(1)

{

for(i=0;i<255;i++)

{

a++;

Po=a;

}

}

}

用8051單片機進行鍵盤編程

矩陣鍵盤是一種模擬開關設備,在許多嵌入式應用中使用,允許用戶執行必要的任務。矩陣鍵盤由行和列中矩陣格式的開關排列組成。行和列連接到微控制器,使得開關行連接到一個管腳,并且每列中的開關連接到另一個管腳,然后執行操作。

  1. WAP to toggle the LED by pressing the switch

#include<reg51.h>

sbit a=P3^0;

sbit b=P3^1;

sbit c=P3^2;

sbit d=P3^3;

void delay();

void main()

{

while(1)

{

a=0;

b=1;

c=1;

d=1;

delay();

a=1;

b=0;

c=1;

d=1;

void delay()

{

unsigned char i;

TMOD=0x20; //set the timer mode//

for(i=0i<2;i++) //double the time daly//

{

TL1=0x19; //set the time delay//

TH1=0x00;

TR1=1; //timer oN//

While(TF1==0); //check the flag bit//

TF1=0;

}

TR1=0; //timer off//

}

  1. WAP to Switch ON the LED by pressing the key ‘1’ on the
    keypad?

#include<reg51.h>

sbit r1=P2^0;

sbit c1=P3^0;

sbit LED=P0^1;

void main()

{

r1=0;

if(c1==0)

{

LED=0xff;

}

}

  1. WAP to display the number 0,1,2,3,4,5 on the seven segment by
    pressing the respective key on the keypad?

#include<reg51.h>

sbit r1=P2^0;

sbit c1=P3^0;

sbit r2=P2^0;

sbit c2=P3^0;

sbit a=P0^1;

void main()

{

r1=0; a=1;

if(c1==0)

{

a=0xFC;

}

If(c2==0)

{

a=0x60;

}

if(c3==0)

{

a=0xDA;

}

If(c4==0)

{

a=0xF2;

}

}

用8051單片機進行液晶顯示編程

LCD顯示器是一種電子設備,在許多應用中經常用于以文本或圖像格式顯示信息。液晶顯示器是一種可以在屏幕上輕松顯示字符的顯示器。液晶顯示器由8條數據線和3條控制線組成,用于與微控制器接口。

WAP to display the “EDGEFX KITS” on LED display ?

#include<reg51.h>

#define kam P0

voidlcd_initi();

voidlcd_dat(unsigned char );

voidlcd_cmd(unsigned char );

void delay();

void display(unsigned char *s, unsigned char r)

sbitrs=P2^0;

sbitrw=P2^1;

sbit en=P2^2;

void main()

{

lcd_initi();

lcd_cmd(0x80);

delay(100);

lcd_cmd(0xc0);

display(“edgefx kits”,11);

while(1);

}

void display(unsigned char *s, unsigned char r)

{

unsignedint w;

for(w=0;w<r;w++)

{

lcd_data(s[w]);

}

}

voidlcd_initi()

{

lcd_cmd(0×01);

delay(100);

lcd_cmd(0×38);

delay(100);

lcd_cmd(0×06);

delay(100);

lcd_cmd(0x0c);

delay(100);

}

voidlcd_dat(unsigned char dat)

{

kam = dat;

rs=1;

rw=0;

en=1;

delay(100);

en=0;

}

}

voidlcd_cmd(unsigned char cmd)

{

kam=cmd;

rs=0;

rw=0;

en=1;

delay(100);

en=0;

}

void delay( unsigned int n)

{

unsignedint a;

for(a=0;a<n;a++);

}

總結

以上是生活随笔為你收集整理的使用Keil语言的嵌入式C编程教程(下)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。