- #include <mega32a.h>
- // Alphanumeric LCD functions
- #include <alcd.h>
- #include <delay.h>
- typedef struct {
- unsigned char pa_dir;
- unsigned char pb_dir;
- unsigned char pc_dir;
- unsigned char pd_dir;
- ////////////////////////////
- unsigned char pa_val;
- unsigned char pb_val;
- unsigned char pc_val;
- unsigned char pd_val;} gpio_ss;
- gpio_ss pins;
- void gpio_init (gpio_ss *x)
- {
- DDRA = x -> pa_dir;
- DDRB = x -> pb_dir;
- DDRC = x -> pc_dir;
- DDRD = x -> pd_dir;
- PORTA = x -> pa_val;
- PORTB = x -> pb_val;
- PORTC = x -> pc_val;
- PORTD = x -> pd_val;
- }
- void set_port(char p_name, unsigned char p_value){
- switch(p_name) {
- case 'A':
- PORTA=p_value;
- break;
- case 'B':
- PORTB=p_value;
- break;
- case 'C':
- PORTC=p_value;
- break;
- case 'D':
- PORTD=p_value;
- break;
- }
- }
- #define In 0x00
- #define Out 0xff
- void main(void)
- {
- pins.pa_dir=Out;
- gpio_init(&pins);
- while (1)
- {
- set_port('A',0xff);
- delay_ms(500);
- set_port('A',0x00);
- delay_ms(500);
- }
- }
Recent Pastes