Digito i/o with Studyboard

Studyboard ‚Basic’ includes three outputs (LED) and three inputs (microswitch) LEDs are connected to PORTC[3..5] and switches PORTC[0..2].

This simple examples demonstrates how to switch on LED when pushing appropriate switch.

Connection schema:

Example C code:

/* Labor 1 example
Example works with Studyboard Basic v3
 
Press S1 - LED1 goes ON
Press S2 - LED2 goes ON
Press S31 - LED3 goes ON
Raivo Sell 2008
 
LED = 0 (ON)  		LED = 1 (OFF)
S	= 0 (ON) 	S	= 1 (OFF)
 
PORT direction: 1-output	0-input */
 
#include <avr\io.h>
 
//defineeritakse kõrge bit pordis x
#define SET(x) |= (1<<x)  
 
//defineeritakse madal bit pordis x
#define CLR(x) &=~(1<<x)  
 
int main(void) {
 
    DDRC  = 0x38;  // DDRC  0bXX111000
    PORTC = 0x3F;  // PORTC 0bXX111111
 
	//Lõputu tsükkel
	while(1) {
		// Kui toimub nupule vajutus
		if (bit_is_clear(PINC, 0))	//Nupp S1
			PORTC CLR(3); //LED 1 sisse
		else if (bit_is_clear(PINC, 1))//Nupp S2
			PORTC CLR(4); //LED 2 sisse
		else if (bit_is_clear(PINC, 2))//Nupp S3
			PORTC CLR(5); //LED 3 sisse
		else //Kui pole midagi vajutatud
			PORTC=0xFF;		//LED lülitatakse välja (LED=1)
	}
}
fi/examples/digi/io.txt · Last modified: 2020/07/20 09:00 by 127.0.0.1
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0