学4412arm基础之波形控制(uart,iic,pwm)

设备间 通讯实现

在这里插入图片描述

串行通讯

单线
双线 uart (全双工 异步)

双线 i2c (半双工 同步)

三线 spi (全双工 同步)

并行通讯

多根数据线 地址线,如内存

串口 UART 协议

在这里插入图片描述
发送 0xFF 0X00 0X04 0X08数据
串行通信参数设置:BAUD:115200,8位数据,1个停止位,无奇偶校验,发送顺序为低位先发送。
在这里插入图片描述

波形实现方法:

1. CPU 已实现,仅需设置寄存器

/*
  功能:   实现k2 interrupt 输出字符显示

  1. 看电路图找到CPU对应的控制管脚   GPX1_1 
  2. 看芯片手册,找到对应寄存器
     a. 配置管脚为interrupt模式
     b. 功能块设置
  3. 编程   

*/


#define GPD0CON         (*(volatile unsigned int *)0x114000A0) 
#define TCFG0           (*(volatile unsigned int *)0x139D0000) 
#define TCFG1           (*(volatile unsigned int *)0x139D0004) 
#define TCNTB0           (*(volatile unsigned int *)0x139D000c) 
#define TCMPB0           (*(volatile unsigned int *)0x139D0010) 
#define TCON             (*(volatile unsigned int *)0x139D0008) 


#define GPX1CON         (*(volatile unsigned int *)0x11000C20) 
#define EXT_INT41CON    (*(volatile unsigned int *)0x11000E04) 
#define EXT_INT41_MASK  (*(volatile unsigned int *)0x11000F04) 
#define ICDISER1_CPU0   (*(volatile unsigned int *)0x10490104) 
#define ICDDCR          (*(volatile  int *)0x10490000)
#define ICCICR_CPU0  (*(volatile  int *)0x10480000)
#define ICCPMR_CPU0  (*(volatile  int *)0x10480004)
#define ICDIPTR14_CPU0 (*(volatile  int *)0x10490838)
#define ICCIAR_CPU0  (*(volatile  int *)0x1048000C)
#define EXT_INT41_PEND (*(volatile  int *)0x11000f44)
#define ICDICPR1_CPU0 (*(volatile  int *)0x10490284)
#define ICCEOIR_CPU0 (*(volatile  int *)0x10480010)
	


#define GPA1CON  (*(volatile unsigned int *)0x11400020) 
#define ULCON2   (*(volatile unsigned int *)0x13820000) 
#define UCON2    (*(volatile unsigned int *)0x13820004) 
#define UBRDIV2  (*(volatile unsigned int *)0x13820028) 
#define UFRACVAL2  (*(volatile unsigned int *)0x1382002c) 
#define UTXH2      (*(volatile unsigned int *)0x13820020) 
#define UTRSTAT2   (*(volatile unsigned int *)0x13820010) 
void uart_init(void)
{
   
  //1. config pin  GPA1_1 GPA1_0  uart mode
  GPA1CON = 0x22;
  //2. set uart function block
  ULCON2  =  0x03;  // data bit =8  parity=none  stop bit=1
  UCON2 = 0x05; //set polling mode
  /*
   * set Baud-Rate = 115200
   * DIV_VAL = (100000000/(115200 *16)) - 1 = 53.253
     UBRDIV2  =50
    UFRACVAL2 = 0x253*16=4
   * 
   */
   UBRDIV2 = 53;  
   UFRACVAL2  = 4;


}

void putc(char c)
{
   
  while(1)
  {
   
	if( UTRSTAT2&0x02)
		break;
  }

   UTXH2 = c; 

}
	
void	interrupt_init()
{
   
  GPX1CON=(GPX1CON&~(0x0F<<4))|(0x0F<<4); //set gpx1_1 interrupt mode   
  EXT_INT41CON =(EXT_INT41CON&~(0x07<<4))|(0x02<<4);//  set GPX1_1 falling edge triger  
  EXT_INT41_MASK = (EXT_INT41_MASK &~(0x01<<1)); //set pin interrupt enable 
  
  ICDISER1_CPU0 = ICDISER1_CPU0 | (1<<25);	//EINT9 (GPX1_1)  GIC中断使能
  ICDIPTR14_CPU0 = 0x01010101; 
  ICDDCR = ICDDCR|1; //GIC 分发总使能
  ICCICR_CPU0 = 1;  // CPU0  中断使能
  ICCPMR_CPU0 = 0XFF;   //设置CPU0的优先级门槛为最低
}

void do_irq(void )
{
   
	  int irq_num;

	  irq_num = ICCIAR_CPU0&0x3ff; 中断ID号
	  switch(irq_num)
	  {
   
      case 57:
	      putc('i');
		  EXT_INT41_PEND = EXT_INT41_PEND|(1<<1);  //清GPX1_1中断标志
		  ICDICPR1_CPU0 = ICDICPR1_CPU0|(1<<25);    //清GIC GPX1_1中断标志
		  break;
      default:
		  putc('e');
		  break
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值