110 likes | 326 Views
Practice. Asst. Prof. Dr. Alper SISMAN. Keypad/7-Segment Display. Keypad Matrix Keypad GND output keypad Serial output keypad Dipswitches 7-Segment Display Ex. Circuit ( HW details resistors etc.). 7-Segment display. Write all decimal numbers on the 7-segment.
E N D
Practice Asst. Prof. Dr. Alper SISMAN
Keypad/7-Segment Display • Keypad • Matrix Keypad • GND output keypad • Serial output keypad • Dipswitches • 7-Segment Display • Ex. Circuit (HW details resistors etc.)
7-Segment display • Write all decimal numbers on the 7-segment. • Design a simple counter (0-9) that counts the seconds.
Use LCD in 4-bit mode #include "STM32F4xx.h" #define RS 32; #define EN 8; #define databits GPIOD->ODR void SystemInit(){ (*((int*)0xE000ED88))|=0x0F00000; // Floating Point donaniminiaktiflestir. RCC->AHB1ENR |= 0x0000000F; // GPIOD->MODER = 0x00005555; GPIOD->OTYPER = 0x0000000F; //GPIOD->PUPDR = 0x00005555; GPIOD->OSPEEDR= 0xFFFFFFFF GPIOB->MODER = 0x00004440; GPIOB->OTYPER = 0x00000028; //GPIOB->PUPDR = 0x00000440; GPIOB->OSPEEDR= 0xFFFFFFFF; }
void cmd(unsigned char c) { GPIOB->BSRRH = RS; delayyus(50); GPIOD->ODR = (c >> 4); LCD_STROBE(); databits = (c); LCD_STROBE(); } void delayyus(int delay0) { delay0-delay0*4; while (delay0--) {} } void LCD_STROBE(void) { GPIOB->BSRRL = EN; delayyus(1); //1us bekle GPIOB->BSRRH = EN; } voidclear(void) { cmd(0x01); delayyus(2000); } void data (unsigned char c) { GPIOB->BSRRL = RS; delayyus(50); //50us bekle databits = (c >> 4); LCD_STROBE(); databits = (c); LCD_STROBE();} void string1(const char *q) { while(*q) { data(*q++); }}
voidlcd_init() { delayy1s(60000); cmd(0x38); delayy1s(4000); cmd(0x38); delayy1s(400); cmd(0x38); cmd(0x28); cmd(0x28); cmd(0x0c); clear(); cmd(0x6); } int main (){ delayyus(50000); lcd_init(); while(1) { cmd(0x80); string1("HELLO WORLD"); cmd(0xc0); string1("IT IS WORKING"); } }
Homework • Write a C code that gets the pushed button if the matrix keypad is used in previous slide. • The ASCII code of the pushed button should be written on a seven-segment display. • Design the HW and Firmware