原创 【瑞萨RL78/G15】+ 评测

2023-9-17 22:34 1343 3 3 分类: MCU/ 嵌入式 文集: 瑞萨
使用E2studio RL78编译环境
一. LED
跟51单片机类似需要手动初始化寄存器
output_ports_configure()函数里面初始化寄存器
  1. /* Port mode registers
  2. * 0 Output mode (output buffer on)
  3. 1 Input mode (output buffer off)
  4. P
  5. 输出高低电平或者读取高低电平
  6. PU
  7. 0 On-chip pull-up resistor not connected
  8. 1 On-chip pull-up resistor connected
  9. POM 输出模式
  10. 0 Normal output mode
  11. 1 N-ch open-drain output (VDD tolerance) mode
  12. */
  13. /* Add code here to setup additional output ports */
  14. PM2 &= ~(1u<<0); /*设置为输出模式*/
  15. P2 |= (1u<<0); /*输出为高电平*/
  16. PU2 &= ~(1u<<0); /*不使用内部上拉*/
  17. POM2 &= ~(1u<<0); /*正常输出模式*/
  18. PMC2&= ~(1u<<0); /*数字IO,替代模拟输入*/
  19. PM2 &= ~(1u<<1);
  20. P2 |= (1u<<1);
  21. PU2 &= ~(1u<<1);
  22. POM2 &= ~(1u<<1);
  23. PMC2&= ~(1u<<1);


主函数翻转LED
  1. void delay(uintmax_t ms)
  2. {
  3. for (int i = 0; i < ms; i++)
  4. {
  5. BSP_NOP();
  6. }
  7. }
  8. PIN_WRITE(2,0) = ~PIN_WRITE(2,0);
  9. PIN_WRITE(2,1) = ~PIN_WRITE(2,1);
  10. /* 延时1s*/
  11. delay(get_fclk_freq_hz());

二.按键控制LED
按键引脚P137默认是输入,不用初始化
  1. /* 按键按下,灯亮,按键按下灯灭*/
  2. uint8_t ping_state = 0;
  3. ping_state = P13_bit.no7;
  4. if (!ping_state)
  5. {
  6. delay(get_fclk_freq_hz() / 100);
  7. if (!ping_state)
  8. {
  9. P2_bit.no0 = 0;
  10. P2_bit.no1 = 0;
  11. }
  12. }else
  13. {
  14. P2_bit.no0 = 1;
  15. P2_bit.no1 = 1;
  16. }

三.按键中断
设置引脚为中断模式
  1. static void interrupts_configure(void)
  2. {
  3. /* Add code here to setup additional interrupts */
  4. /* P137/INTP0
  5. *
  6. */
  7. EGP0_bit.no0 = 1; /* P137双边沿触发*/
  8. EGN0_bit.no0 = 1;
  9. MK0L_bit.no1 = 0; /* 使用中断服务函数*/
  10. BSP_NOP();
  11. } /* End of function interrupts_configure() */
四.OLED显示
引脚初始化
  1. PM0_bit.no6 = 0; /*设置为输出模式*/
  2. PM0_bit.no7 = 0;
  3. P0_bit.no6 = 1; /*输出为高电平*/
  4. P0_bit.no7 = 1;
  5. PU0_bit.no6 = 0; /*不使用内部上拉*/
  6. PU0_bit.no7 = 0;
  7. POM0_bit.no6 = 0; /*开漏输出模式*/
  8. POM0_bit.no7 = 0;
  9. PMC0_bit.no6 = 0; /*数字IO,替代模拟输入*/
  10. PMC0_bit.no7 = 0;

Oled初始化
  1. OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
  2. OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  3. OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  4. OLED_WR_Byte(0x40,OLED_CMD);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
  5. OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
  6. OLED_WR_Byte(0xCF,OLED_CMD);// Set SEG Output Current Brightness
  7. OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常
  8. OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
  9. OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
  10. OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  11. OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
  12. OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
  13. OLED_WR_Byte(0x00,OLED_CMD);//-not offset
  14. OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
  15. OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  16. OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
  17. OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  18. OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
  19. OLED_WR_Byte(0x12,OLED_CMD);
  20. OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
  21. OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
  22. OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
  23. OLED_WR_Byte(0x02,OLED_CMD);//
  24. OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
  25. OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
  26. OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
  27. OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
  28. OLED_Clear();
  29. OLED_WR_Byte(0xAF,OLED_CMD);
  30. OLED_DisPlay_On();

作者: 莫羨, 来源:面包板社区

链接: https://mbb.eet-china.com/blog/uid-me-4040671.html

版权声明:本文为博主原创,未经本人允许,禁止转载!

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条