1 / 15

----51 系列单片机 C 语言编程入门

嵌入式 C 语言之. ----51 系列单片机 C 语言编程入门. 通过本次课的学习,你会学到. 典型 51 单片机特点(功能); 51 单片机的引脚结构; 51 单片机的 IO 使用方法; 51 单片机下中断的使用方法; 51 单片机下定时器使用例程; 51 单片机下串行通信例程;. 典型 51 单片机: AT89C51. 8051 内核,最高外接晶振 24MHz ; 32 个 I/O 引脚对应 4 个 8 位 I/O 端口; 2 个 16 位定时器; 6 个中断源, 2 种优先级; 1 个 UART 串行口 , 4KB FLASH 程序存储器 ,

jerome-paul
Download Presentation

----51 系列单片机 C 语言编程入门

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 嵌入式C语言之 ----51系列单片机C语言编程入门

  2. 通过本次课的学习,你会学到 • 典型51单片机特点(功能); • 51单片机的引脚结构; • 51单片机的IO使用方法; • 51单片机下中断的使用方法; • 51单片机下定时器使用例程; • 51单片机下串行通信例程;

  3. 典型51单片机:AT89C51 • 8051内核,最高外接晶振24MHz; • 32 个I/O引脚对应4个8位I/O端口; • 2个16位定时器; • 6个中断源,2种优先级; • 1个UART串行口, • 4KB FLASH程序存储器, • 128B的RAM; • 可外扩存储器;

  4. AT89C51系统结构图(放大后观看)

  5. 51单片机的典型引脚结构 • AT89C51

  6. 51单片机的IO使用方法 • P0口是8位双向I/O端口,对应P0_0到P0_7共8个引脚; • 作为输出端口,输出驱动能力很小(典型值2mA); • 每个引脚能允许8路TTL输入,当对P0的某个引脚x写入1之后,读取P0_x能得知此时外部加在P0_x引脚上的电平 • P0_0=1; // 想从P0_0输入,先置1 • bool isHigh=P0_0; // 从P0_0读数据

  7. 51单片机的I/O输出例子 #include <REG51.H> main() { P0=0x55; while(1); }

  8. 51单片机的I/O输入例子 #include <AT89X51.H> main() { char i=0; P3_0=1; while(1) { if(P3_0==0) { P1=i++; } } }

  9. 51单片机的中断系统 • 基本的51单片机支持6个中断源,其中 • 2个外部中断,INT0(P3.2),INT1(P3.3) • 2个记数器中断,T0(P3.4),T1(P3.5) • 2个串行中断,RXD(P3.0),TXD(P3.1) • 每个中断都有自己的中断入口地址,Keil对其进行了编号,如下所示:

  10. Keil中断函数的中断号码

  11. 中断函数的编写 void ex0_isr (void) interrupt 0 // EINT0 { //your codes here } void ex0_isr (void) interrupt 1 // T0 { //your codes here } 如何对中断初始化呢?

  12. 51单片机的中断控制寄存器

  13. 以INT0为例说明中断程序写法

  14. INT0例程 #include <REG52.H> unsigned char ex0_counter = 0; void ex0_isr (void) interrupt 0 { P0=ex0_counter++; //加一送P0显示 } void main (void) { IT0 = 1; // INT0 下降沿触发 EX0 = 1; // 使能INT0 EA = 1; // 开总中断 while (1) ; //死循环 }

  15. 课后作业 • 根据我给出的内容自学51单片机定时器0和串行通信程序。争取每条语句都能看懂。 • 参考内容: • Keil C51 硬件编程手册.pdf8051_counter0.zip8051_ex0.zip8051_uart.zip

More Related